7 Replies Latest reply on May 24, 2007 8:42 AM by gavin.king

    @Startup not working

    maniappan

      I am trying to start a scheduler when my application starts up.

      @Entity
      @Name("mySchedule")
      @Table(name="my_schedule")
      @Scope(ScopeType.SESSION)
      @Startup
      public class MySchedule
       implements Serializable,
      {
      
       public void MySchedule()
      {
      MyScheduleHome msh = (MyScheduleHome) Component.getInstance("myScheduleHome");
      msh.Schedule();
      log.debug("Timer activated");
      }
      //Rest of the getters/setters for table.
      ...
      }
      

      I invoked the Schedule from one of my other application object and it worked. I want to call Schedule during application startup and don't see it being invoked.

      I don't see any error or information in the log[in Debug mode] related to the @Startup.

      What could be the issue here?


        • 1. Re: @Startup not working
          javabr

          Hi,

          It is working for me: (take a loog on @Create)

          @Startup(depends="manager")
          @Name("controller")
          @Scope(ScopeType.APPLICATION)
          public class Controller {
          
           @In(create=true)
           private Manager manager;
          
           @Create
           public void create() throws Exception {
           manager.schedule();
           }
          }
          



          @Name("manager")
          @Scope(ScopeType.APPLICATION)
          public class Manager {
          
           private static Date MIDNIGHT = null;
          
           @In(create = true)
           Job sendNotificationsToScheduledTasks;
          
           public void schedule() {
           Calendar calendar = GregorianCalendar.getInstance();
           calendar.set(Calendar.HOUR_OF_DAY, 0);
           calendar.set(Calendar.MINUTE, 1);
           calendar.set(Calendar.SECOND, 1);
           MIDNIGHT = calendar.getTime();
           System.out.print(MIDNIGHT);
           sendNotificationsToScheduledTasks.execute(MIDNIGHT, Frequency.DAILY.getInterval());
           }
          


          I also had must to take the jboss timer off.

          rgds
          Leo





          • 2. Re: @Startup not working
            javabr

            opsss.

            and also de Job interface:

            @Local
            public interface Job {
            
             @Asynchronous
             @Transactional
             public Timer execute(@Expiration
             Date startDate, @IntervalDuration
             long interval);
            
            }
            


            • 3. Re: @Startup not working
              maniappan

              Hi Leo,
              I earlier tried it the way you had done[start it in application scope] and it worked. I want to move it to Startup.
              Cheers, Mani

              • 4. Re: @Startup not working
                javabr

                Oooohh I am sorry...

                I am fresh meat here.. so I am just using what I am looking around.

                If I figure out something I back to u.

                bests
                Leo

                • 5. Re: @Startup not working

                  In your example this

                  public void MySchedule()
                  


                  Is wrong. That's not a constructor it's a method. Remove the void.

                  You can use the constructor method but a better way is to use the @Create annotation instead.

                  @Entity
                  @Name("mySchedule")
                  @Table(name="my_schedule")
                  @Scope(ScopeType.SESSION)
                  @Startup
                  public class MySchedule
                   implements Serializable,
                  {
                  
                   @Create
                   public void create()
                  {
                  MyScheduleHome msh = (MyScheduleHome) Component.getInstance("myScheduleHome");
                  msh.Schedule();
                  log.debug("Timer activated");
                  }
                  //Rest of the getters/setters for table.
                  ...
                  }
                  


                  I would also suggest having @Entity and @Startup is bad practice. Your entity object should be relatively clean and the scheduling code should probably be in a session bean that may inject/create the entity bean.

                  Cheers.

                  Mike.

                  • 6. Re: @Startup not working
                    maniappan

                    Mike,
                    I renamed to create as suggested by you and made it a APPLICATION Scope. Also had to add @Local since JNDI couldn't lookup the object during start and it has started working.

                    Thanks, Mani.

                    • 7. Re: @Startup not working
                      gavin.king

                      Since it is a session scope component, it starts when the session starts, not when the application starts.