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

标签 java tomcat quartz-scheduler

有一点不太清楚。假设我全天随机安排工作,每项工作需要 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/

相关文章:

JavaFX 在 WebEngine 中禁用突出显示和复制模式

java - 在java中获取远程tcp连接的ip地址?

java - TOMCAT_OPTS、环境变量和 System.getEnv()

java - Quartz 的 CronTrigger 每两个小时

java - 调整 TYPE_CUSTOM BufferedImages 的大小?

eclipse - 从 Eclipse 启动时无法访问 Tomcat

java - 启用 JPA 静态编织(eclipselink)

java - Quartz 在启动时运行作业

java - 如何更改集群 quartz 作业的时间表?

java - 当每个请求可以到达多个服务器时,如何维护用户凭据