当执行job出现异常的时候如何处理?
1.将这个exception包装为JobExecutionException
try {
int zero = 0;
int calculation = 4815 / zero;
} catch (Exception e) {
System.out.println("--- Error in job!");
JobExecutionException e2 =
new JobExecutionException(e);
// this job will refire immediately
e2.setRefireImmediately(true);
throw e2;
}
2.设置JobExecutionException的属性
如果 e2.setRefireImmediately(true);
则在检测到异常后重新执行job
如果 e2.setUnscheduleAllTriggers(true);
则检测到异常后会退出job
更多的属性用到的时候再google
本文介绍了一种处理Job执行中出现异常的方法:通过抛出JobExecutionException并设置不同属性来决定是否立即重试或退出任务。
1万+

被折叠的 条评论
为什么被折叠?



