Search code examples
javaquartz-schedulerjobs

Quartz Scheduler - Ignore misfired job - withMisfireHandlingInstructionDoNothing() not working


I want to ignore any misfired jobs (say when the service was down) and just wait until next schedule.

For this i tried below :

TriggerBuilder.newTrigger().withIdentity(jobName, jobGroup)
            .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)
                      .withMisfireHandlingInstructionDoNothing())
            .withPriority(jobPriority).build();

This job triggers weekly on every Tuesday. Say on one Tuesday, the service was down and it comes up on Friday. Then the job should trigger on next Tuesday and not when the service comes up.

But above code is not working. the job is triggered as soon the service comes up.

Note: I am manually forwarding the time to test this.(In case if this makes any difference)


Solution

  • I think i got it.

    For the MisfireHandlingInstruction to take effect, the delay should be greater than the value set by

    org.quartz.jobStore.misfireThreshold = 60000

    or else the quartz never treats the trigger as misfire. so the misfire instruction wont take effect.

    From here

    Before I dive into the details, there is yet another configuration option that should be described. It is org.quartz.jobStore.misfireThreshold (in milliseconds), defaulting to 60000 (a minute). It defines how late the trigger should be to be considered misfired. With default setup if trigger was suppose to be fired 30 seconds ago, Quartz will happily just run it. Such delay is not considered misfiring. However if the trigger is discovered 61 seconds after the scheduled time - the special misfire handler thread takes care of it, obeying the misfire instruction. For test purposes we will set this parameter to 1000 (1 second) so that we can test misfiring quickly.