3 Replies Latest reply on Apr 16, 2009 10:12 AM by Björn Raupach

    Starting a timer on application start

    Björn Raupach Newbie

      Hi,


      maybe someone can help me with this one: For a maintance task I would like to run a stateless session bean timer once a day. I thought the combination with the Startup Annotation from Seam is the way to go, but nothing happens. Any ideas?


      @Stateless
      @Startup
      @Name("someTask")
      @Scope(ScopeTye.APPLICATION)
      public class SomeJobBean implements SomeJob {
      
        private static boolean isTimerSet;
      
        @Logger Log log;
      
        @Resource TimerService timerService;
      
        @PostConstruct
        public void initSomeJob() {
          if (!isTimerSet) {
            log.info("initSomeJob()");
            long dayInMillis = 1000 * 60 * 60 * 24;
            timerService.createTimer(new Date(),now.getTimeInMillis);
            isTimerSet = true;
          }
        }
      
        @Timeout
        public void doSomeTask(Timer timer) {
          log.info("doSomeTask");
          // some more business logic
        }
      }
      



      I am using Seam 2.1.1 and JBoss AS 4.2.3


      Thanks in advance!