如果作业面临Java异常,我们需要重新启动Quartz作业,最多可达5次。
但是当我们尝试从主要的Exception
调用这些方法中的任何一个时JobExecutionException je;
je.refireImmediately();
je.setRefireImmediately(true);
重击不会发生。
使用的Quartz版本是1.7.3
请协助。
答案 0 :(得分:0)
您已经接近,但是您需要重新抛出新创建的异常。该代码在2.1.6中有效,但是在1.X中,您可能需要在JobDataMap中手动增加/存储重新发射计数。
try {
whatever();
} catch (Exception e) {
// Retry this job up to 5 times.
if (context.getRefireCount() < 4) {
logger.warn("job_failure attempt={}", context.getRefireCount());
throw new JobExecutionException(e, true);
} else {
throw e;
}
}