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.
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.
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.
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.
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.
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.
set
org.quartz.threadPool.threadCount=1
There will be a single quartz worker thread at a time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With