2 Replies Latest reply on Feb 29, 2012 1:35 PM by negora

    TimerService.getTimers () returns an empty collection. Is it a bug?

    negora

      Hello everybody:

       

      I'm still a newbie of Java EE, but something which worked for me in JBoss AS 5 is not working in JBoss AS 7 any longer. On the one hand, I inject the TimerService into a statless session bean this way:

       

         @Resource

         private TimerService timerService;

       

       

      On the other hand, into a method where I want to list which Timers have been registered, I do:

       

      Collection <Timer> timers = timerService.getTimers ();

       

      Even though I've registered one or more Timers succesfully (I know it because I've set a log to check this), this sentence always returns an empty collection. Is this a bug or an expected behaviour?

       

      Thank you.

        • 1. Re: TimerService.getTimers () returns an empty collection. Is it a bug?
          sfcoy

          That call will only return timers associated with the bean into which the TimerService was injected.

           

          ie. the bean containing the

           

          {code:java}@Resource

          private TimerService timerService;{code}

           

          must also contain a method marked up with @Timeout.

           

          If that's the case then you must also be sure that the timer has not expired.

          • 2. Re: TimerService.getTimers () returns an empty collection. Is it a bug?
            negora

            Stephen Coy wrote:

             

            That call will only return timers associated with the bean into which the TimerService was injected.

             

             

            Oh my bad! :S I didn't remember that, when I migrated my application to JBoss AS 7, I also changed the place where I queried the TimerService. Indeed, I was querying for a Timer into a different bean from where I created it (believing that timers where "shared" among classes of the same EJB application). Obviosuly, in JBoss AS 5 it worked because I instantiated and queried in the same bean.

             

            Thank you a lot .