Timers are created in EJB3 using the TimerService.createTimer()
, and are then run via whatever callback method that's annotated by the @Timeout
annotation, i.e:
@Resource
private TimerService timerService;
public void createHampster() {
Hampster hampster = new Hampster("Fluffy III");
timerService.createTimer(3000, 3000, hampster);
}
(...)
@Timeout
public void feedHampster(Timer timer) {
Hampster hampster = (Hampster) timer.getInfo()
//(...)
}
So, my question is, do these two blocks of code need to be within the same bean? Are timers inherit to the bean in which they were created, or are they global? My own testing suggests but former, and I haven't found anything definite in the documentation.