4 Replies Latest reply on Feb 13, 2015 8:50 AM by eperez15

    Sheduled EJB3  with reload a deploy.

    eperez15

      Dear all

       

      I have scheduled ejb by programatic dates (but is the same with anottations)   with Wildfly 8.2.0.   when I reload the jar (and change the Timer scheduled)   Wildfly conserve the old programers and I have to delete all Timers from:

       

      wildfly-8.2.0.Final/standalone/data/timer-service-data

       

      I atach you example code:

       

      @Singleton(mappedName = "ListSchedule")

      @Startup

      @Lock(LockType.WRITE)

       

      @AccessTimeout(value = 0)

       

      public class TaskSchedule2 implements Serializable{

        

       

       

       

          /**

           *

           */

          private static final long serialVersionUID = 6309408448344242965L;

          private static final Logger LOGGER = LoggerFactory.getLogger(TaskSchedule2.class);

        

         

          @Resource TimerService timerService;

          /**

           * Default constructor.

           */

          public TaskSchedule2() {

             

          }

          @PostConstruct

          public void initialize(){

         

         

              try {

                 

            ScheduleExpression expression =new ScheduleExpression();

           

            expression.second(10).minute("*").hour("*");

           

               timerService.createCalendarTimer(expression);

           LOGGER.info(" programing Schedule with timer:{}",expression);

                 

             

              } catch ( NullPointerException  e) {

            LOGGER.error("Not possible initialize scheduled tasks:{}",e);

           

              }

        }

       

         

          @Timeout

          private void scheduledTimeout(final Timer t) {

                

                 LOGGER.info("Run at {}",new java.util.Date());

          }

         

       

      }

       

      the logs::

      (ServerService Thread Pool -- 81)  programing Schedule with timer:ScheduleExpression[second=10 minute=* hour=* dayOfWeek=* dayOfMonth=* month=* year=* start=null end=null timezone=]

      (EJB default - 1) Run at Thu Feb 12 18:13:10 CST 2015

      (EJB default - 2) Run at Thu Feb 12 18:14:10 CST 2015

      (EJB default - 3) Run at Thu Feb 12 18:15:10 CST 2015

       

       

       

       

      Later, I change expression.second(10).minute("*").hour("*");  to expression.second(30)..minute("*").hour("*");   Compile, replace jar in Wildfly and the logs:

      (ServerService Thread Pool -- 90)  programing Schedule with timer:ScheduleExpression[second=30 minute=* hour=* dayOfWeek=* dayOfMonth=* month=* year=* start=null end=null timezone=]

      (EJB default - 4) Run at Thu Feb 12 18:15:30 CST 2015

      (EJB default - 5) Run at Thu Feb 12 18:16:10 CST 2015

      (EJB default - 6) Run at Thu Feb 12 18:16:30 CST 2015

      (EJB default - 7) Run at Thu Feb 12 18:17:10 CST 2015

       

      I can solve getting in @PostConstruct   all timers and delete it, but  I think when I un-deploy or replace jar, Wildfly has to delete all data of old jar. It's an Issue?

       

      Thanks you in advance

        • 1. Re: Sheduled EJB3  with reload a deploy.
          wdfink

          Hi Ernesto,

           

          There is no explicit description, but in general the timers are supposed to e persistent by default. This mean if you create one it will be persisted. If you use annotations it should be removed if the method is gone, not sure what happen if you change the schedule for a persistent method

           

          But if you create the timer programatically you can set the TimerConfig to be non persistent. That ensure that the timer is not persisted, as in your case you create it each time you start/deploy it.

          • 2. Re: Sheduled EJB3  with reload a deploy.
            ctomc

            Wolf-Dieter Fink wrote:

             

            Hi Ernesto,

             

            There is no explicit description, but in general the timers are supposed to e persistent by default. This mean if you create one it will be persisted. If you use annotations it should be removed if the method is gone, not sure what happen if you change the schedule for a persistent method

             

            if you use annotations to define timers, you should set persistant=false, see http://docs.oracle.com/javaee/7/api/javax/ejb/Schedule.html for more

            1 of 1 people found this helpful
            • 3. Re: Sheduled EJB3  with reload a deploy.
              wdfink

              Done a short test.

              If you use annotation and redeploy the application with a changed @Schedule annotaion the schedule will be changed.

              But if it is persistent all events are fired if you restart the server or have a longer period of 'undeploy' state and some of it are missed.

               

              BTW the correct name for the attribute is @Schedule(...... persistent="false")

              • 4. Re: Sheduled EJB3  with reload a deploy.
                eperez15

                Thanks you. Now,  I understand better the Persistent in scheduled.   I change to:

                 

                     TimerConfig  conf=new TimerConfig();
                     conf.setPersistent(false);
                    
                     timerService.createCalendarTimer(expression,conf);

                 

                 

                And resolve the problem.