John
John

Reputation: 887

Having quartz execute a job only in one thread when there are multiple quartz threads

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.

Upvotes: 8

Views: 16449

Answers (3)

sumant kumar
sumant kumar

Reputation: 1

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.

Upvotes: 0

jhouse
jhouse

Reputation: 2692

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.

Upvotes: 25

Dhananjay
Dhananjay

Reputation: 3975

set

org.quartz.threadPool.threadCount=1

There will be a single quartz worker thread at a time

Upvotes: 2

Related Questions