3 Replies Latest reply on Sep 19, 2007 4:30 PM by gbc1

    how to terminate @Asynchronous method

    tjakopec

      I have @Asynchronous method and everithing is working fine. Now I want to stop calling that method.

      @AutoCreate
      @Name("natjecajServis")
      @Stateless
      public class NatjecajServisBean implements NatjecajIServis {
      @Asynchronous
       public void odradi(@Expiration
       Date date, @IntervalCron
       Long interval,@FinalExpiration Date kraj) {
      ...
      }
      }
      


      witch is call from another bena when server starts
      @Stateless
      @Name("cron")
      public class CronBean implements Cron {
      @In
      ZaposlenikIServis zaposlenikServis;
      @Observer("org.jboss.seam.postInitialization")
      public void postaviIzvodenje() {
       log.info("Set up cron");
      zaposlenikServis.odradi(...);
      }
      }
      



      So, how to stop calling @Asynchronous method

        • 1. Re: how to terminate @Asynchronous method
          gbc1

          Do you use Quartz or EJB Timers?

          Doc Reference (CR1): http://docs.jboss.com/seam/2.0.0.CR1/reference/en/html/jms.html#d0e11316[/url]

          • 2. Re: how to terminate @Asynchronous method
            tjakopec

            I don't use quartz, but I didn't also use classic EJB timers (I read http://docs.jboss.com/seam/2.0.0.CR1/reference/en/html/jms.html#d0e11316)

            I just annotated method with @Asynchronous ant its working for me

            @Asynchronous = import org.jboss.seam.annotations.async.Asynchronous;

            Help with approach is appreciated!

            • 3. Re: how to terminate @Asynchronous method
              gbc1

              Look deeper into 18.1.1:

              The Timer object shown below is the EJB3 timer when you use the EJB3 dispatcher. For the default ScheduledThreadPoolExecutor, the returned object is Future from the JDK. For the Quartz dispatcher, it returns QuartzTriggerHandle, which we will discuss in the next section.

              So you just need to declare your Method on the Interface to return this special object and implement it that way:

              a) A Future object (with default scheduler, java.util.concurent i think):
               public Future odradi(@Expiration
               Date date, @IntervalCron
               Long interval,@FinalExpiration Date kraj) {
               return whatever; // will be ignored
               }
              

              b) acoording to this a Timer object for EJB3 (javax.ejb i think)Timers or
              c) a QuartzTriggerHandle object

              You will receive this object immidiatly and may sace it into Context, a map in an Application scoped manager or whereever. With this Object you are able to stop the timed call (I'm working with quartz and it just works)

              Hope this is what helps you out,

              Greetz GHad