7 Replies Latest reply on Dec 16, 2007 4:51 PM by Pete Muir

    Asynchronous method triggered multiple times.

    Vincent Faidherbe Newbie

      I've a Stateless local Session Bean which defines an asynchronous method which is launched at startup by an observer method.

      Everything works fine except that the method is triggered multiple times simultaneously. Any idea why?

      Neither the TimeService implementation nor the Quartz implementation solves the issue.

      Here's the Session Bean interface:

      @Local
      public interface SendMailJob {
      
       @Asynchronous
       public void processMailQueue(@Duration long start, @IntervalDuration long interval);
      
      }
      



      Here's the Session Bean implementation:

      @Stateless(name = "SendMailJob")
      @Name("sendMailJob")
      public class SendMailJobImpl implements SendMailJob {
      
       @Resource(name="jdbc/luxair_asr_Datasource")
       private DataSource dataSource;
      
       @Resource(name="mail/luxair_asr_MailSession")
       private Session mailSession;
      
      
       @Logger
       private Log log;
      
      
       public void processMailQueue(long start, long interval) {
      
       // ...
       }
      }
      


      Here's the component that launches the asynchronous method at startup:

      @Name("sendMailJobLauncher")
      public class SendMailJobLauncher {
       private long interval;
      
       public void setInterval(long interval) {
       this.interval = interval * 60 * 60 * 1000;
       }
      
       // ========
       // Resource
       // ========
      
       @In(create = true)
       private SendMailJob sendMailJob;
      
       @Logger
       private Log log;
      
       @Observer("org.jboss.seam.postInitialization")
       public void statup() {
       log.info("startup() launch sendMailJob [interval: {0}]", interval);
       sendMailJob.processMailQueue(2 * 60 * 1000, interval);
       }
      }