8 Replies Latest reply on Apr 1, 2008 9:36 AM by Oskar Carlstedt

    How to start a session bean as soon as it is deployed

    Masoodah Ahmed Newbie

      Hi,

      I want a session bean or other to start as soon as I deploy the application. Basically my need is to access a certain table in the database periodically using @Timeout Timer Serivce.
      My bean looks like so
      @Stateless
      public class AdSetScheduleBean implements AdSetScheduleRemote, AdSetScheduleLocal {

      // Add business logic below. (Right-click in editor and choose
      // "EJB Methods > Add Business Method" or "Web Service > Add Operation")


      public AdSetScheduleBean() {
      }

      @PostConstruct
      public void init() {
      System.out.println("I am in Postconstructor of AdSetScheduleBean");

      }

      @Resource TimerService timerService;

      //Method to be called on timer expiration
      @Timeout
      public void CheckAdSetSchedule( Timer timer ){
      // Define method here

      }

      public void startTimer(){
      System.out.println("I am in startTimer");
      long timeNow = System.currentTimeMillis();
      long interval = 5;

      timerService.createTimer(timeNow, interval, null);
      }
      }

      How do I wake this bean on startup and have it check Status ar regular intervals.
      Thanks