Quartz can run a lot of jobs but see how thread pools can limit how many jobs can execute simultaneously
示例:我们一次加载500个JOB,500个Trigger到同一个Scheduler对象中。然后再执行sched.start();
正常情况,不考虑资源时,500个任务会同时执行。但是由于我们在quartz.properties配置的org.quartz.threadPool.threadCount大小有限,所以一次只能执行线程大小的数量。正常情况会出现大量的misfire,但使用requestRecovery重新恢复执行,则不会触发misfire,会直接重新执行。
注:如果这时程序中断,而job又设置了RequestsRecovery为true,则该job会被重新执行(不受misfireThreshold影响,因为根本就不是misfire)。
可以通过JobExecutionContext.isRecovering()来判断是否是recover,因为很多时候恢复的任务要先做一些清理工作。
关于requestRecovery与misfire参考下面问答:
您好,如果我是数据库服务异常中断了一些任务,程序还在跑,当数据库服务正常后,又超过了设置的 misfireThreshold时间,那任务还会不会继续执行呢?如果不执行了那怎么处理让任务继续执行?谢谢!
如果程序正常,那job是正常执行完成(正常结束或异常结束)。
既然结束了,那就和misfireThreshold没关系了。
另外单独重新启动job吧
谢谢您的回答,重新调度这个JOB是一个方法,但是我发现我的数据服务正常后,显然超过了misfireThreshold设置时间,我没有设置RequestsRecovery属性,但任务还是可以正常运行,对于这quartz的业务流程不是很清楚,楼主怎么理解,是否可以给我详解下,谢谢。
就算数据库出问题了,但如果你job代码里对exception做了处理,没有导致job出错,那job运行状态就是正常的,和recovery、misfire就没关系。
比如数据库连接不上会一直重试
From <http://kanbol.iteye.com/blog/1129945>
quartz jobDetail requestRecovery
up vote 7 down vote favorite
The documentation for JobDetail.requestsRecovery property states the following
Instructs the Scheduler whether or not the Job should be re-executed if a 'recovery' or 'fail-over' situation is encountered.
Now, what is a 'recovery' situation or a 'fail-over' situation?
How are they different?
Does the recovery happen only if the JVM crashes during job execution or does it happen if the job execution fails because of an exception also?
1 Answer
up vote 6 down vote
A "Recovery situation" is the generic term, one kind of recovery situation is the "fail-over".
A fail-over is a process used by fault-tolerance systems generally used with redundancy (e.g. clustering). Quartz use fail-over when is used in clustering and more Quartz "nodes" exists.
Quoting documentation:
Fail-over occurs when one of the nodes fails while in the midst of executing one or more jobs. When a node fails, the other nodes detect the condition and identify the jobs in the database that were in progress within the failed node. Any jobs marked for recovery (with the "requests recovery" property on the JobDetail) will be re-executed by the remaining nodes.
A recovery situation is every situation that produce an "Hard-shutdown" (i.e. the process it is running within crashes, or the machine is shut down).
To answer your second question:
- If the JVM crashes during a job execution > Quartz will recover the job
(Because a crash is Recovery situation) - if the job execution fails because of an exception > Quartz will not recover the job
(Because exception is not an hard-shutdown, a misfire is thrown instead)
See this answer to activate recovery for your jobs.
From <https://stackoverflow.com/questions/19267263/quartz-jobdetail-requestrecovery>
quartz.properties
------------------------------------------------------------------------------------------------------------
#===================