Quartz当前正在执行作业

Quartz当前正在执行作业

本文介绍了当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".

引用官方文档:

所以你可以做例子:

import static org.quartz.JobBuilder.*;

...

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

...

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

07-26 01:19