Quartz current executing job when Tomcat is killed

我只是一个虾纸丫 提交于 2019-11-29 07:00:15

Short answer, by default, currently running Jobs are considered fired and are not recovered

..but you can set requestRecovery property when you build a Job (JobDetail) to tell Quartz to recover that running Jobs in case of crash a.k.a. "hard shutdown".

Quoting the official documentation here on the bottom of the page:

RequestsRecovery - if a job "requests recovery", and it is executing during the time of a 'hard shutdown' of the scheduler (i.e. the process it is running within crashes, or the machine is shut off), then it is re-executed when the scheduler is started again. In this case, the JobExecutionContext.isRecovering() method will return true.

So you can do for exemple:

import static org.quartz.JobBuilder.*;

...

JobDetail job = newJob(MyJob.class)
           .withIdentity("myJob", "group1")
           .requestRecovery(true) //This is the guy!
           .build();

...

Tomcat does not care about your job. It is your task to terminate the job correctly in your webapp when it is shut down.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!