2 Replies Latest reply on Mar 6, 2009 1:05 AM by jaikiran

    EJB Timer Service issue - Executes multiple times

    kanag_k

      Hi

      I created a SLSB timer service. On calling the scheduleTimer() method from my testcase the timer is created but the timeout method is executed multiple times. It waits for the specified duration(1 min) and again executes multiple times. is there any specific reason.

      I thought it might be because of pooling so I used the PoolClass to limit the pool size to 1. Below is the EJB code

      ***********************************************************

      import java.rmi.RemoteException;
      import java.util.Date;

      import javax.annotation.PostConstruct;
      import javax.annotation.Resource;
      import javax.ejb.EJBException;
      import javax.ejb.Remote;
      import javax.ejb.SessionContext;
      import javax.ejb.Stateless;
      import javax.ejb.Timeout;
      import javax.ejb.Timer;
      import javax.jws.WebService;

      import org.apache.log4j.Logger;
      import org.jboss.annotation.ejb.PoolClass;


      @Stateless
      @PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=1)
      public class HealthCheckTimerBean implements HealthCheckTimer
      {
      private static Logger log = Logger.getLogger(HealthCheckTimerBean.class);

      private static @Resource SessionContext ctx;


      public void scheduleTimer() throws RemoteException
      {
      long interval =60000;

      System.out.println("HC Interval: "+interval);

      if(interval<1)
      {
      log.error("Cannot create Health Check timer - HC interval not defined");
      throw new RemoteException("Cannot create Health Check timer - HC interval not defined");
      }
      ctx.getTimerService().createTimer(interval,interval, "Probe Health Check Timer");
      }

      @Timeout
      public void timeoutHandler(Timer timer)throws RemoteException
      {
      System.out.println("---------------------");
      System.out.println("* Received Timer event: " + timer.getInfo());
      System.out.println("---------------------");
      }
      }

        • 1. Re: EJB Timer Service issue - Executes multiple times
          kanag_k

          Also this is what get printed in the logs continuously

          2009-03-05 10:29:16,162 DEBUG [org.jboss.ejb.txtimer.TimerImpl] Timer was not registered with Tx, resetting state: [id=1236266846001,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-66901297,periode=60000,in_timeout]
          2009-03-05 10:29:16,162 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: active
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] run: [id=1236266846004,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-3563093,periode=60000,active]
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: in_timeout
          2009-03-05 10:29:16,177 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,177 INFO [STDOUT] * Received Timer event: Probe Health Check Timer
          2009-03-05 10:29:16,177 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] Timer was not registered with Tx, resetting state: [id=1236266846004,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-3503093,periode=60000,in_timeout]
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: active
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] run: [id=1236266846003,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-68412437,periode=60000,active]
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: in_timeout
          2009-03-05 10:29:16,177 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,177 INFO [STDOUT] * Received Timer event: Probe Health Check Timer
          2009-03-05 10:29:16,177 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] Timer was not registered with Tx, resetting state: [id=1236266846003,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-68352437,periode=60000,in_timeout]
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: active
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] run: [id=1236266846005,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-66961297,periode=60000,active]
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: in_timeout
          2009-03-05 10:29:16,177 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,177 INFO [STDOUT] * Received Timer event: Probe Health Check Timer
          2009-03-05 10:29:16,177 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] Timer was not registered with Tx, resetting state: [id=1236266846005,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-66901297,periode=60000,in_timeout]
          2009-03-05 10:29:16,177 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: active
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] run: [id=1236266846008,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-3563094,periode=60000,active]
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: in_timeout
          2009-03-05 10:29:16,193 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,193 INFO [STDOUT] * Received Timer event: Probe Health Check Timer
          2009-03-05 10:29:16,193 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] Timer was not registered with Tx, resetting state: [id=1236266846008,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-3503094,periode=60000,in_timeout]
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: active
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] run: [id=1236266846006,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-3563094,periode=60000,active]
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: in_timeout
          2009-03-05 10:29:16,193 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,193 INFO [STDOUT] * Received Timer event: Probe Health Check Timer
          2009-03-05 10:29:16,193 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] Timer was not registered with Tx, resetting state: [id=1236266846006,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-3503094,periode=60000,in_timeout]
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: active
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] run: [id=1236266846007,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-67889719,periode=60000,active]
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: in_timeout
          2009-03-05 10:29:16,193 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,193 INFO [STDOUT] * Received Timer event: Probe Health Check Timer
          2009-03-05 10:29:16,193 INFO [STDOUT] ---------------------
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] Timer was not registered with Tx, resetting state: [id=1236266846007,target=[target=jboss.j2ee:service=EJB3,ear=InventoryServices.ear,jar=InventoryOperationsEJB.jar,name=HealthCheckTimerBean],remaining=-67829719,periode=60000,in_timeout]
          2009-03-05 10:29:16,193 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: active


          • 2. Re: EJB Timer Service issue - Executes multiple times
            jaikiran

             

            the timer is created but the timeout method is executed multiple times. It waits for the specified duration(1 min) and again executes multiple times. is there any specific reason.


            That's because, you configured the timer to do so :)

            ctx.getTimerService().createTimer(interval,interval, "Probe Health Check Timer");


            Have a look at the javadocs of createTimer, the second parameter mentions the repeat interval. I think you want this, instead:

            ctx.getTimerService().createTimer(interval, "Probe Health Check Timer");