1 Reply Latest reply on May 9, 2007 10:26 AM by Pete Muir

    probelm with asynchronous methods and timers

    Fredrik Newbie

      I have a usecase where I want to have a recurring service checking some db information and send out mails i nessesary. I started with a simple scheduled service that worked fine. Then I wanted to use Seam to send out my mails but I got problems with failed rendering because I was outside of the seam context in my scheduled service bean. So I switch to using seam asynchronous methods and timers.

      I have a bootstrap action annotated with
      @Startup(depends={"org.jboss.core.jndi", "org.jboss.core.jta"})
      and then a @Create annotated method to start the asynchronous action with a timer.
      The boostrap action is application scoped and stores the timer instance for the duration of the application lifecycle. The timer is destroyed in the @destroy method. When the timer is created it is stored by the application server in the timer db table and removed when the server is stoped or my application undeployed.

      Now to the problem :-)
      Sometimes the timer is not removed from the db when the server is stopped. Then when I start the server again a new timer is created in my bootstrap action and now I have to timers running making my service run more often then I want.

      How can I avoid this problem? Is this the wrong solution for my usecase or can I somehow check for exising timers when bootstrapinig or can I shedule my asynchronous methos in the same way that i schedule my service in a xml file or ... ?

      Thankfull for all input!

      Best regards Fredrik