users@glassfish.java.net

EJB3 Timers

From: <glassfish_at_javadesktop.org>
Date: Tue, 15 May 2007 13:38:14 PDT

Hey,
I was wondering how Timers work, their lifecycle, etc...

I have about three/four Stateless EJB3 beans with timers,


Most of the EJBs timers part look like this:

@Stateless()
public class MyBean implements SomeInterface {

@Resource
TimerService timerService;

public void anyMethod() {
  timerService.createTimer(initialMs,durationMs,null);
}

@Timeout
public void someMethodToInvoke(Timer timer) {
   //Do something
}
}




I have few questions I am not sure about:

1) Is there -one- TimerService per application server ? or there is a TimerService per EJB? if EJBs are stateless, how TimerService is persistence?

2) How do I create different method callbacks associated to different timers? is it possible at all? or when one of the timers times-out, all methods annotated with @Timeout, no matter in what EJB will be invoked?

3) It appears that when a timer times-out, it only invokes the methods annotated with @Timeout -on its own- EJB scope,

So assuming I created two different timers(TimerX,TimerY) from two different EJBs, EjbX, EjbY, when TimerX times-out, it only invokes the methods annotated with @TImeout on EjbX.

is this the normal behavior?, what is strange is that when I cancel one's EJB timer, all of my timers stops working so,

although I canceled -1- timer (I counted by ejb->timerService.getTimers().size()), on one of th eEJBs, all the others timers stopped triggering too (had about other 3 on different EJBs)


Thanks,

Asaf.
[Message sent by forum member 'trouby' (trouby)]

http://forums.java.net/jive/thread.jspa?messageID=217138