1 Reply Latest reply on Aug 28, 2006 11:05 AM by wdfink

    TimedObject question.

    uborba

      Hi,

      I wrote a class:

      public class PnaScheduleFacade implements SessionBean, TimedObject {
       public void ejbTimeout(Timer arg0) {
       // task code.
       }
      
       public TimerHandle createTimerHandle(long interval) {
       TimerService timerService = context.getTimerService();
       Timer timer = timerService.createTimer(interval, interval, null);
       return timer.getHandle();
       }
      
      }
      


      and another class to start the service:
      public class PnaScheduler implements Schedulable {
      
       public void perform(Date arg0, long arg1) {
       if(!started) {
       PnaScheduleFacadeLocal psLocal = EJBUtil.findLocalObject(PnaScheduleFacadeLocal.class);
       TimerHandle handle = psLocal.createTimerHandle(interval);
       System.out.println("Handle = " + handle);
       started = true;
       }
       }
      
      }
      



      The schedule does it fine, but every time I restart my JBoss it will create
      another Timer, and JBoss will also restart old Timers that are serialized, I need to check in code if there is already a Timer that restarts the service and create another one only if necessary.

      Thanks for any help/directions.

        • 1. Re: TimedObject question.
          wdfink

          in your EJB createTimerHandle() you should ask the timerService for existing timers with getTimers().
          If you only one (looks like, theres no info) you skip the creation if the Collection is not empty.