Probably a silly question for someone with ejb experience...
I want to read and change the minute parameter dynamically for one of my EJB beans that uses the Java EE scheduler via the @Schedule
annotation. Anyone know how to do this at runtime as opposed to hardcoding it in the class like below? If i were to do it programatically could i still use the @Schedule
annotation?
@Schedule(dayOfWeek = "0-5", hour = "0/2", minute = "0/20", timezone = "America/Los_Angeles")
private void checkInventory() {
}
@Schedule
is for automatic timers created by the container during deployment.On the other hand, you can use
TimerService
which allows you to define at runtime when the@Timeout
method should be called.This might be interesting material for your: The Java EE 6 Tutorial - Using the Timer Service.
EDIT: Just to make this answer more complete. If it's a matter of is it possible than the answer would be - yes, it is.
There is a way to "change the parameters" of automatic timer created with
@Schedule
. Nevertheless it's quite extraordinary - it cancels the automatic timer and creates a similar programmatic one:Once again - personally, I would never use such code and would never want to see anything like this in a real project :-) Either the timer is:
@Schedule
by hard-coding the values or by defining them in ejb-jar.xml,