当有多个quartz线程时,让quartz仅在一个线程中执行一项作业

发布于 2024-11-27 17:22:30 字数 328 浏览 0 评论 0原文

我想知道是否可以配置quartz 来执行在任何给定时间仅在一个线程中运行的长时间处理作业。换句话说,假设我配置了大小为 5 的 SimpleThreadPool 的quartz。我有一个每 10 秒触发一次的作业,但在某些情况下可能需要超过 10 秒才能完成。有没有办法配置石英触发器/作业/调度程序,以便该触发器不会再次触发,因为它已经在另一个线程中处于运行状态。当触发器再次触发时,池中的另一个线程将拾取它并同时运行同一作业的两个实例。感谢您的意见。

说明:(有关使用大小为 1 的线程池的建议)。要求是将线程池配置为 5 个线程,并且任何单个作业在任何给定时间仅在单个线程中执行,换句话说,作业的实例只能由一个线程执行。

I was wondering if one can configure quartz to execute a long processing job run only in one thread at any given time. In another words, say I have quartz configured with a SimpleThreadPool of size 5. And I have a job that fires every 10 seconds but that could take longer than 10 seconds to complete in certain situations. Is there a way to configure quartz trigger/job/scheduler so that this trigger won't fire again as it is already in a running state in another thread. When the trigger fires again, another thread from the pool will pick it up and have two instances of the same job run at the same time. Thanks for your input.

Clarification: (for the suggestions about using a threadpool of size 1). Requirement is to configure the threadpool with 5 threads and have any single job to execute only in a single thread at any given time, in other words an instance of a job should be executed by only one thread.

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

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

发布评论

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

评论(3

情定在深秋 2024-12-04 17:22:30

如果您使用 Quartz 1.x,请让 Job 类实现 StatefulJob。如果您使用的是 Quartz 2.x,则将 @DisallowConcurrentExecution 注释添加到作业类中。

If you're using Quartz 1.x make the Job class implement StatefulJob. If you're using Quartz 2.x then add the @DisallowConcurrentExecution annotation to the job class.

心凉 2024-12-04 17:22:30

set

org.quartz.threadPool.threadCount=1

一次会有一个单一的quartz工作线程

set

org.quartz.threadPool.threadCount=1

There will be a single quartz worker thread at a time

过气美图社 2024-12-04 17:22:30

在集群环境中,您是否会依赖数据库锁来确保没有两个线程运行相同的quartz作业?

不仅如此,我还遇到了quartz.threadpool.threadcount设置为10的实现。

数据库变得疯狂,线程也变得疯狂,因为它们不断地出现“无法获取”锁异常。

In a clustered environment would you ever rely on database lock to ensure that no two threads run the same quartz job ever?

Not only this I came across an implementation where the quartz.threadpool.threadcount is set to 10.

The DB is going crazy, threads are going crazy too as they are constantly getting ‘unable to acquire’ lock exception.

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