Using Spring’s integration api with Quartz, what will the effects be on cron jobs that have uncaught exceptions? Since the cronbean/worker thread did not catch the exception, will that mean the thread is dead and will not be able to go back to the SimpleThreadPool? If its dead and does not get back to the pool will that mean the SimpleThreadPool will need to create new threads, if say this happens multiple times thus emptying out the pool?
This is a sample the stack trace:
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)**
The
JobRunShellclass is a sandbox in which job execution takes place. It contains acatch (Throwable)clause that catches everything that is not aJobExecutionExceptionand logs the error. Worker threads are returned to pool in any case.So, the answer is no, unhandled exceptions do not break Quartz thread pools. Trigger implementations could behave differently (for example unschedule or delete the trigger) in the
executionCompletemethod.This said, Quartz documentation explicitly advices against throwing any exceptions out of your job except
JobExecutionException: