5 Replies Latest reply on Feb 24, 2010 7:57 AM by Prem Chand

    Problem with Quartz @IntervalCron on startup

    Prem Chand Newbie


      I'm trying to create a scheduled task that runs every day at the given time. And i had a requirement to run this task after some time the server is started. Say 5 minutes after the server start up.

      So, i'm setting @Expiration date to 5 minutes after the server startup. It is not triggering the action when the time expires initially, but works properly for subsequent timeouts as set in the cron string.

      Here is my implemetation:-

      public class BillingScheduler implements Serializable {
           private static final long serialVersionUID = 323760983458853226L;
           private Log log;
           private BillingProcessor billingProcessor;
           private QuartzTriggerHandle callLogTriggerHandle;
          private static String CL_CRON_INTERVAL = "0 30 23 * * ?";
          public void scheduleBillingTasks() {
               try {
                    Calendar cal = Calendar.getInstance();
                    cal.add(Calendar.MINUTE, 5);
                    cal.set(Calendar.SECOND, 0);
                    Calendar cal2 = Calendar.getInstance ();
                    cal2.set(3000, Calendar.MAY, 10);
                    log.info("############### Scheduling Call Log Cron Job.........");
                    log.info("Setting Call Log Initial Timeout to ::::::::: "+cal.getTime());
                    callLogTriggerHandle = 
                         billingProcessor.createCallLogCronJob(cal.getTime(), CL_CRON_INTERVAL, cal2.getTime());
               } catch (Exception e) {
                    log.error("Error!!!!", e);

      public class BillingProcessor {
           private Log log;
           public QuartzTriggerHandle createCallLogCronJob(
                     @Expiration Date when, 
                     @IntervalCron String interval,
                     @FinalExpiration Date endDate) {
                String date = new Date().toString();          
                log.info("@@@@@@@@@@@@@@ Call Log Quartz Test: " + date);
                QuartzTriggerHandle handle = new QuartzTriggerHandle("CallLogTrigger");
                return handle;

      Also, i had added these lines in my components.xml file :-

      <event type="org.jboss.seam.postInitialization"> 
          <action execute="#{billingScheduler.scheduleBillingTasks}"/>

      Please help me in this regard and let me know if i'm doing something wrong.