Ensure that Spring Quartz job execution doesn#39;t overlap(确保 Spring Quartz 作业执行不重叠)
问题描述
我有一个 Java 程序,它每 20 秒从 Spring Qquartz 执行一次.有时只需几秒钟即可执行,但随着数据变大,我确信它会运行 20 秒或更长时间.
I have a Java program that executes from Spring Qquartz every 20 seconds. Sometimes it takes just few seconds to execute, but as data gets bigger I'm sure it run for 20 seconds or more.
如何防止 Quartz 在一个实例仍在执行时触发/触发作业?解雇 2 个在数据库上执行相同操作的作业不会那么好.有没有办法进行某种同步?
How can I prevent Quartz from firing/triggering the job while one instance is still being executed? Firing 2 jobs performing same operations on a database would not be so good. Is there a way I can do some kind of synchronization?
推荐答案
如果你需要做的只是每 20 秒开火一次,那么 Quartz 是严重的矫枉过正.java.util.concurrent.ScheduledExecutorService
应该足以胜任这项工作.
If all you need to do is fire every 20 seconds, Quartz is serious overkill. The java.util.concurrent.ScheduledExecutorService
should be perfectly sufficient for that job.
ScheduledExecutorService
还提供了两种调度语义."fixed rate" 将尝试每 20 秒运行一次作业,而不管是否重叠,而 "固定延迟" 将尝试在第一个作业结束和下一个作业开始之间留出 20 秒.如果你想避免重叠,那么固定延迟是最安全的.
The ScheduledExecutorService
also provides two semantics for scheduling. "fixed rate" will attempt to run your job every 20 seconds regardless of overlap, whereas "fixed delay" will attempt to leave 20 seconds between the end of the first job and the start of the next. If you want to avoid overlap, then fixed-delay is safest.
这篇关于确保 Spring Quartz 作业执行不重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:确保 Spring Quartz 作业执行不重叠
基础教程推荐
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 在螺旋中写一个字符串 2022-01-01