javaquartz-scheduler

Quartz's CronTrigger for every 8 hours fails - java


I have setup cron expression, to run job at every 8 hours

trigger.setCronExpression("0 0/480 * * * ?");

but this is not working fine. job runs every after 1 hour.

Java / Quartz Scheduler

CronTrigger trigger = new CronTrigger();
   trigger.setName("data-checks-job");
   trigger.setStartTime(CommonUtil.getBeforeTimeInHour("1", "yyyy/MM/dd-HH:mm:ss"));
   trigger.setCronExpression("0 0/480 * * * ?"); 

Solution

  • Your expression is not valid. You can't exceed the 24 on the hours section:

    Hours:

    "0/8" means every 8 hours starting at hour 0.

    Every 8 hours valid Cron Expression:

    0 0 0/8 ? * * *