简体   繁体   English

当Tomcat被杀死时,Quartz当前正在执行作业

[英]Quartz current executing job when Tomcat is killed

Something i am not clear on. 我不清楚的事情。 Say i have jobs randomly scheduled throughout the day and each job takes 30 minutes to run. 假设我在一天中随机安排了工作,每个工作需要30分钟才能运行。 Say i have five of these jobs running and Tomcat gets killed. 假设我有五个这样的工作正在运行而且Tomcat被杀死了。 Do the jobs restart when i start Tomcat with my application, or are the currently running jobs lost because they already fired? 当我使用我的应用程序启动Tomcat时,是否重新启动作业,或者当前正在运行的作业因为已经被解雇而丢失了?

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 aka "hard shutdown". .. 但是你可以在构建一个Job(JobDetail)时设置requestRecovery属性,告诉Quartz在崩溃的情况下恢复正在运行的Jobs,即“硬关机”。

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 (ie the process it is running within crashes, or the machine is shut off), then it is re-executed when the scheduler is started again. RequestsRecovery - 如果一个作业“请求恢复”,并且它正在调度程序的“硬关闭”期间执行(即它在崩溃中运行的进程,或者机器被关闭),那么它将被重新执行当调度程序再次启动时。 In this case, the JobExecutionContext.isRecovering() method will return true. 在这种情况下,JobExecutionContext.isRecovering()方法将返回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. Tomcat不关心你的工作。 It is your task to terminate the job correctly in your webapp when it is shut down. 在关闭时,您的任务是在webapp中正确终止作业。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM