Reputation: 2291
I have a quartz job:
public class GlobalIdleMonitorJob extends AbstractJob {
@Override public void execute(JobExecutionContext context)
throws JobExecutionException {
try {
getJobService().processUserIdle();
}catch(Exception e){
getLogger().error("GlobalIdleMonitorJob",e);
}
}
}
This job runs every X seconds. I want this job to stop after first failure. In other words, if
getJobService().processUserIdle();
threw an exception, I want this job not run anymore, only after manual restart or web app server restart. Should I throw a special exception in catch block or how to configure it?
Upvotes: 2
Views: 1449
Reputation: 5616
In your catch block you can unschedule a job like this:
try {
getJobService().processUserIdle();
} catch(Exception e) {
scheduler.unscheduleJob(triggerKey)
getLogger().error("GlobalIdleMonitorJob",e);
}
If you don't have any other trigger or job in your app, you can simply call scheduler.clear()
, but this could not be a good idea if you are likely to add new jobs or triggers in the future.
Upvotes: 0
Reputation: 56
You can just set the setUnscheduleAllTriggers method of JobExecutionException class object to true(true). Refer the below attached example from the official quartz website for you reference.
Upvotes: 1