Reputation: 2598
I want a process to run everyday at an specific hour of the day everyday. I want to use the Timerservice of EJB's but I can only find how to set an interval, not an specific hour of the day:
@Resource
protected TimerService timerService;
@Timeout
public void timeoutHandler(Timer timer) {
String name = timer.getInfo().toString();
System.out.println("Timer name=" + name);
}
public void startOrModifyTimer(long initialExpiration, long interval, String name){
//Cancel previous timer
Collection<Timer> timers = timerService.getAllTimers();
for (Timer timer: timers) {
if (timer.getInfo().equals(name)) {
timer.cancel();
}
}
TimerConfig config = new TimerConfig();
config.setInfo(name);
config.setPersistent(false);
timerService.createIntervalTimer(initialExpiration, interval, config);
}
I want to change the timer from "Every day at 2am" to "Everyday at 3am" on runtime.
Upvotes: 0
Views: 188
Reputation: 118593
You want:
createCalendarTimer(ScheduleExpression schedule)
The ScheduleExpression will do what you want.
Upvotes: 1