编程语言
首页 > 编程语言> > java-石英计划的作业无法触发-可能未处理的异常?

java-石英计划的作业无法触发-可能未处理的异常?

作者:互联网

我有一个使用Quartz库的具有预定作业的Web应用程序.最近,我遇到了一些工作似乎没有被解雇的情况.我做了一些阅读,显然如果作业抛出异常,Quartz调度程序将尝试再次执行作业.这是真的?

无论如何,我都基于上述陈述是正确的假设进行了一些故障排除.因此,假设我有以下代码段:

try {
   method.invoke(object, params);
}
catch (ExceptionA ea) {
   ea.printStackTrace();
}
catch (ExceptionB eb) {
   eb.printStackTrace();
}
// and so on so forth, catching a bunch of specific Exceptions

这里要注意的重要一点是,Exception本身并未被捕获.

因此,假设正在调用的方法将引发未处理的异常.

public void methodBeingInvoked() throws UnhandledException {

这里会发生什么?

解决方法:

从Job抛出的任何Throwable将被Quartz捕获并包装在JobExecutionException中,并且不会被重新触发.
查看JobRunShell#run的源代码

有一些documentation on the Quartz website与此矛盾,但是在查看Quartz 1.8.x / 2.0.x / 2.1.x源代码之后,该文档对于所有版本都是错误的.

A Job’s execute method should contain a try-catch block that handles
all possible exceptions.

If a job throws an exception, Quartz will typically immediately
re-execute it (and it will likely throw the same exception again).
It’s better if the job catches all exception it may encounter, handle
them, and reschedule itself, or other jobs. to work around the issue.

标签:scheduler,exception,quartz-scheduler,java
来源: https://codeday.me/bug/20191102/1988814.html