gpt4 book ai didi

java - Tomcat 被杀死时 Quartz 当前正在执行的作业

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:08:39 25 4
gpt4 key购买 nike

有一点不太清楚。假设我全天随机安排工作,每项工作需要 30 分钟才能运行。假设我有五个这样的工作在运行,而 Tomcat 被杀死了。当我用我的应用程序启动 Tomcat 时作业会重新启动,还是当前正在运行的作业会丢失,因为它们已经被触发?

最佳答案

简答,默认情况下,当前正在运行的 Jobs 被认为已解雇并且不会恢复

..但是您可以在构建作业 (JobDetail) 时设置 requestRecovery 属性,以告诉 Quartz 在崩溃的情况下恢复正在运行的作业,也就是“硬关机” .

引用官方文档here在页面底部:

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();

...

关于java - Tomcat 被杀死时 Quartz 当前正在执行的作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19139796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com