1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
@Stateless(name = "ProgramaticTimer", mappedName = "ProgramaticTimer")
public class ProgramaticTimerBean {
@Resource
TimerService timerService;
@EJB
private FluxFacade jpaSessionFacade;
FluxController f;
public ProgramaticTimerBean() {
}
@Timeout
public void doProcess(Timer timer) {
System.out.println("Programatic Timer got invoked at " + new Date());
//mon traitement
f.run();
}
public void startScheduler(String h,String m,String s,String schedulerId){
ScheduleExpression scheduleExpression = new ScheduleExpression();
scheduleExpression.hour(h).minute(m).second(s);
timerService.createCalendarTimer(scheduleExpression, new TimerConfig(schedulerId, true));
System.out.println("Programatic Timer got created succesfully");
}
public void stopScheduler(String schedulerId) {
if (timerService.getTimers() != null) {
for (Timer timer : timerService.getTimers()) {
if (timer.getInfo().equals(schedulerId)) {
timer.cancel();
System.out.println("Programatic Timer got stopped succesfully");
}
}
}
}
} |