当Tomcat被杀死时,Quartz当前正在执行作业 [英] Quartz current executing job when Tomcat is killed

查看:100
本文介绍了当Tomcat被杀死时,Quartz当前正在执行作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不清楚的事情。假设我在一天中随机安排了工作,每个工作需要30分钟才能运行。假设我有五个这样的工作正在运行而且Tomcat被杀死了。当我使用我的应用程序启动Tomcat时,是否重新启动作业,或者当前正在运行的作业因为已经解雇而丢失了?

Something i am not clear on. Say i have jobs randomly scheduled throughout the day and each job takes 30 minutes to run. Say i have five of these jobs running and Tomcat gets killed. Do the jobs restart when i start Tomcat with my application, or are the currently running jobs lost because they already fired?

推荐答案

短答案,默认情况下,当前正在运行的作业被视为已被解雇并且未被恢复

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

.. 您可以设置 requestRecovery 属性,当你构建一个Job(JobDetail)来告诉Quartz恢复正在运行的作业,以防崩溃,也就是硬关机。

..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".

引用官方文档这里


RequestsRecovery - 如果作业请求恢复,并且它在调度程序的
'硬关闭'期间执行(即它在崩溃中运行
的过程,或者机器被关闭),然后在再次启动调度程序时重新执行
。在这种情况下,
JobExecutionContext.isRecovering()方法将返回true。

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.

所以你可以做例子:

import static org.quartz.JobBuilder.*;

...

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

...

这篇关于当Tomcat被杀死时,Quartz当前正在执行作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆