Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 916
John Avatar asked Aug 02 '11 21:08

John


People also ask

How do Quartz jobs work?

Quartz scheduler allows an enterprise to schedule a job at a specified date and time. It allows us to perform the operations to schedule or unschedule the jobs. It provides operations to start or stop or pause the scheduler. It also provides reminder services.

How do you trigger multiple jobs in quartz scheduler?

If you want to schedule multiple jobs in your console application you can simply call Scheduler. ScheduleJob (IScheduler) passing the job and the trigger you've previously created: IJobDetail firstJob = JobBuilder.

Is Quartz thread safe?

Assuming you are using a standard configuration of Quartz (storing jobs and triggers in RAM instead of a persistent JobStore), then it appears that Quartz is thread safe.

How do I stop Quartz running?

deleteJob(jobKey(<JobKey>, <JobGroup>)); This method will only interrupt/stop the job uniquely identified by the Job Key and Group within the scheduler which may have many other jobs running.


2 Answers

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.

like image 178
jhouse Avatar answered Oct 13 '22 02:10

jhouse


set

org.quartz.threadPool.threadCount=1

There will be a single quartz worker thread at a time

like image 26
Dhananjay Avatar answered Oct 13 '22 00:10

Dhananjay