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:
@Singleton
public class CustomTimer {
@EJB
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?
Well You need to created Two Scheduler One Scheduler will run to update data from Database Based On that You Can created Other Scheduler.
But for this Need to do it some what programmatic. You also can see EJB Timers for the same what will help you in this case. which is also annotation based.
There is a simple way of doing this. I wanted to something that called a process every day but, the job itself should be done randomly over the same day. I managed to do that by adding a simple thread worker to run after the EJB timer service has been called. Then I would put it to sleep for a random amount of time during that day.
The following code is an example of a service that wakes up every 1 minute and waits for a thread to finish.
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.