javadev javadev - 1 year ago 136
Java Question

Dynamic parameters for @Schedule method in an EJB 3.x

I'm new to the @Schedule annotations in J2EE6

I want to run a job using EJB 3.x with Glassfish 3.1.

The javax.ejb.Schedule seems to be a good choice for us, so we could think of our custom time as something like:

public class CustomTimer {
SettingsFacade settingsFacade;

@Schedule(second="someSecondParameter", minute="someMinuteParameter",hour="someHourParameter", persistent=false)
public void executeTimer(){
//Code executing something against database using the settingsFacade

Here, we want the parameters to be got from database, so they are changed every month. Any clean solution for this?

Answer Source

No, there is no solution with @Schedule, because annotation attributes in general should be compile time constants.

When more flexibility is needed, programmatic timers can be used. Also then polling database for changed configuration and removing existing and creating new timers must be implemented.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download