未捕获的异常对Quartz的SimpleThreadPool中的线程的影响

Car*_*eon 1 java spring quartz-scheduler worker-thread threadpool

使用Spring的集成API Quartz,对具有未捕获异常的cron作业有什么影响?由于cronbean/worker线程没有捕获异常,这是否意味着该线程已经死亡并且无法返回到SimpleThreadPool?如果它死了并且没有返回池将意味着SimpleThreadPool将需要创建新线程,如果这样多次发生,从而清空池?

这是堆栈跟踪的示例:

org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:276) - Invocation of method 'doCronJob' on target class [abc.package.ServiceImpl] failed
java.io.FileNotFoundException: http://www.website.com
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1457)
    at abc.package.ServiceImpl.doCronJob(ServiceImpl.java:453)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:283)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:272)
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:208)
    **at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)**
Run Code Online (Sandbox Code Playgroud)

Emi*_*uch 5

JobRunShell班是一个沙箱中工作执行发生.它包含一个catch (Throwable)捕获非a的所有内容JobExecutionException并记录错误的子句.在任何情况下,工作线程都会返回池中.

所以,答案是否定的,未处理的异常不会破坏Quartz线程池.触发器实现在方法中的行为可能不同(例如,取消计划或删除触发器)executionComplete.

这就是说,Quartz文档明确建议不要在你的工作中抛出任何异常,除非JobExecutionException:

最后,我们需要告知您有关Job.execute(..)方法的一些细节.允许从execute方法抛出的唯一异常类型(包括RuntimeExceptions)是JobExecutionException.因此,您通常应该使用'try-catch'块来包装execute方法的全部内容.您还应该花一些时间查看JobExecutionException的文档,因为您的作业可以使用它来为调度程序提供有关如何处理异常的各种指令.