0 Replies Latest reply on Mar 13, 2008 7:32 AM by Cristi Cioriia

    How EJB timer works

    Cristi Cioriia Newbie

      Hi,
      I have used a timer that repeatedly fires with a given frequency and detected a behavior that seems strange to me. So I would like to ask your opinion about this.
      I have a timer that expires every 3 minutes. The timer fires as I expected for the first times:


      19:10:00,484 INFO [AlertServiceEJB] Executing timer: [id=1,target=[target=jboss.j2ee:service=EJB3,ear=wise-ear.ear,jar=wiccore-alert.jar,na
      me=AlertServiceEJB],remaining=180000,periode=180000,in_timeout]
      19:10:00,484 INFO [AlertServiceEJB] Remaining time: 180 Next timeout: Wed Mar 12 19:13:00 GMT 2008
      19:13:00,484 INFO [AlertServiceEJB] Executing timer: [id=1,target=[target=jboss.j2ee:service=EJB3,ear=wise-ear.ear,jar=wiccore-alert.jar,na
      me=AlertServiceEJB],remaining=180000,periode=180000,in_timeout]
      19:13:00,484 INFO [AlertServiceEJB] Remaining time: 180 Next timeout: Wed Mar 12 19:16:00 GMT 2008
      19:16:00,500 INFO [AlertServiceEJB] Executing timer: [id=1,target=[target=jboss.j2ee:service=EJB3,ear=wise-ear.ear,jar=wiccore-alert.jar,na
      me=AlertServiceEJB],remaining=179984,periode=180000,in_timeout]
      19:16:00,500 INFO [AlertServiceEJB] Remaining time: 179 Next timeout: Wed Mar 12 19:19:00 GMT 2008

      After this I stopped the server and started it again and this is what I got:

      19:16:42,000 INFO [AlertServiceEJB] Executing timer:
      [id=1,target=[target=jboss.j2ee:service=EJB3,ear=wise-ear.ear,jar=wiccore-alert.jar,na
      me=AlertServiceEJB],remaining=-221516,periode=180000,in_timeout]
      19:16:42,015 INFO [AlertServiceEJB] Remaining time: -221 Next timeout: Wed Mar 12 19:13:00 GMT 2008
      19:19:41,937 INFO [AlertServiceEJB] Executing timer: [id=1,target=[target=jboss.j2ee:service=EJB3,ear=wise-ear.ear,jar=wiccore-alert.jar,na
      me=AlertServiceEJB],remaining=-221453,periode=180000,in_timeout]
      19:19:41,937 INFO [AlertServiceEJB] Remaining time: -221 Next timeout: Wed Mar 12 19:16:00 GMT 2008

      So, when the server is restarted the timer is fired like it had never fired previously: the Next timeout value is 19:13 and the remaining value is -221 = -(3 * 60 + 21) which subtracted from 19:16:42 gives 19:13 again.
      This is very awkward to me. I would have expected that the timer was persisted in such a way that only missed firings will be fired at server restart. Since I stopped the server after the timer fired and started it before the next time the timer was supposed to fire, I would expect that nothing happens at server startup, because the timer did not missed any firings.
      Another thing that I have noticed is that when the timer is persisted the information that was associated to the timer when the timer was persisted is also persisted, but if this information is changed when the timer fires, this change is not persisted and at server restart the timer uses the information from creation time.
      Is there any way to change this behavior(by configuration) or this is the expected behavior? I use JBOSS 4.2.1.