views:

419

answers:

1
+1  Q: 

TimerService EJB 3

Hi, Related to TimerService, can I define two Timer instances and bind each timer to a specific (different) method annotated @Timeout in the same EJB?

Thanks, Rod

+2  A: 

Not really.

However, you can define 2 timers

ctx.getTimerService().createTimer(1000, 1000, "timerA");
ctx.getTimerService().createTimer(1000, 1000, "timerB");

and have one timeout method to handle the timeout of both timers.

@Timeout
  public void handleTimeout(Timer timer) {
    String info = (String)timer.getInfo();
    if ( "timerA".equals(info) { handleTimerEventA(); }
    else if ( "timerB".equals(info) { handleTimerEventB(); }
}
Ryan Fernandes