Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz exception handling

I have the following quartz job. I made some test with it.

public void execute(JobExecutionContext context) throws JobExecutionException {
    try {

        Object result = callable.call();

    } catch (Exception e) {
        JobExecutionException e2 = new JobExecutionException(e);
        if (REFIRE_IMMEDIATELY.equals(policy)) {
            e2.setRefireImmediately(true);
        } else if (UNSCHEDULE_ALL_TRIGGERS.equals(policy)) {
            e2.setUnscheduleAllTriggers(true);
        } else {
            e2.setUnscheduleFiringTrigger(true);
        }
        throw e2;
    }
}

But I can't fully understand what is the difference between setUnscheduleAllTriggers and setUnscheduleFiringTrigger. And unfortunately there is no Javadoc.

Does someone can help me ?

Thanks

like image 830
Pith Avatar asked Feb 15 '23 01:02

Pith


1 Answers

In quartz you can have multiple triggers firing your job. If the reason for the job execution to fail is inherent in the trigger, you may want to unschedule that specific trigger. That is my understanding of setUnscheduleFiringTrigger(true).

If the problem is with the job itself and not the trigger, it would fail on every execution, no matter who or what started it. So to save yourself the hassle of multiple executions failing, just because different triggers fire the job, you can use setUnscheduleAllTriggers(true) to unschedule all the triggers firing this job, preventing any further executions of the faulty job.

So to summarize

  • setUnscheduleFiringTrigger => Stop the trigger that called this specific job-run
  • setUnscheduleAllTriggers => Stop all triggers calling this job

See http://www.quartz-scheduler.org/documentation/2.4.0-SNAPSHOT/examples/Example6.html for an example of the Exception's usage.

like image 102
sheltem Avatar answered Feb 20 '23 11:02

sheltem