集群模式下的 Spring 和 Quartz 集成不会覆盖现有作业

发布于 2024-11-18 06:17:17 字数 488 浏览 4 评论 0原文

我正在使用 Spring 3 和 Quartz 1.8.5 以集群模式安排作业。我已经在 Spring 的调度程序配置中放置了 overwriteExistingJobs=true 。

除了使用 Quartz 作业配置的作业之外,我还需要以编程方式创建动态作业。一切正常,直到我重新启动服务器。此时overwriteExistingJobs=true就有问题了。

假设我创建了一个动态作业,每两分钟执行一次。而且,我停止服务器并在十分钟后启动它,该作业在服务器启动后立即执行五次。但是,如果有一项作业是 spring 配置的一部分,例如 spring 文档中给出的作业,那么当服务器重新启动时,它会被覆盖。

我的观察是,对于在 spring 配置文件中配置并添加到 org.springframework.scheduling.quartz.SchedulerFactoryBean 的作业, QRTZ_TRIGGERS 表中的 PREV_FIRE_TIME 更新为“-1”,但对于动态创建的作业,它不会被覆盖。

I am using Spring 3 and Quartz 1.8.5 to schedule jobs in a clustered mode. I have placed, overwriteExistingJobs=true in the Spring's scheduler configuration.

There is a requirement for me to create dynamic jobs programmatically apart from the jobs which are part of the configuration using Quartz jobs. Everything works fine till i re-start the server. At this point , there is a problem with overwriteExistingJobs=true.

Say, if i have a dynamic job created to execute every two minutes. And, i stop the server and start it after ten minutes, the job executes five times as soon as the server starts. But, if there is a job which is part of the spring configuration , like the one given in spring documentation , it is over-written when the server re-starts.

My observation has been that for jobs which are configured in the spring configuration file and added to the org.springframework.scheduling.quartz.SchedulerFactoryBean, the
PREV_FIRE_TIME in QRTZ_TRIGGERS table gets updated to '-1' but for dynamically created jobs it is not over-written.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卖梦商人 2024-11-25 06:17:17

修复如下:

a) 我有与动态作业关联的 CronTriggers,所以我所做的是提供失火指令。

JobDetail jobDetail = new JobDetail(job.getDescription(), job.getName(),job.getClass());
CronTrigger crTrigger = new CronTrigger( "cronTrigger", job.getName(), cronExpression);
crTrigger.setStartTime(firstFireTime);
crTrigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
scheduler.scheduleJob(jobDetail, crTrigger);

b)失火阈值相当高(6000000)。所以,我所做的就是降低失火阈值,而且效果非常好。

The fix is as follows:

a) I have CronTriggers associated with dynamic jobs so what i did was to provide the mis-fire instruction.

JobDetail jobDetail = new JobDetail(job.getDescription(), job.getName(),job.getClass());
CronTrigger crTrigger = new CronTrigger( "cronTrigger", job.getName(), cronExpression);
crTrigger.setStartTime(firstFireTime);
crTrigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
scheduler.scheduleJob(jobDetail, crTrigger);

b)The mis-fire threshold was pretty high (6000000). So, what i did was to reduce the misfire threshold and it worked like a charm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文