1 Reply Latest reply on Jun 17, 2011 6:04 PM by lvdberg

    How to (re)start or stop the default Timer ?

    serkan.s.eskici.online.nl

      Hi,


      I'm using the default Timer in Seam to start asynchronous or interval jobs with the @Duration and @Interval annotations.


      But I don't know how to stop and restart an interval job that is already running.


      I can't use @In Timer since this is the EJB timer and I get exceptions if I do this.


      Any help or tip is appreciated, thx !

        • 1. Re: How to (re)start or stop the default Timer ?
          lvdberg

          Hi,


          Let's assume you have a class with following method:



          class YourTimer ...
          
          @Transactional
          @Asynchronous
          public QuartzTriggerHandle checkMessages(@Expiration Date when,
                    @IntervalDuration Long interval, @FinalExpiration Date endDate){                 process();
               return null;
               }




          This timer is called from a bean YourBean:




          class YourBean ....
          
          @In(create=true) YourTimer yourTimer;
          
          private QuartzTriggerHandle timerHandle;
          
          



          Which  somewhere in the bean calls:






          timerHandle = yourTimer.checkMessages(cal.getTime(), 600000L, null);
          





          After the call you have a handle of the timer and you can do what you want.
          Although it looks strange. The Timer method is intercepted, so it returns a handle instead of the null.


          Hopefully this helps a bit.


          Leo