How to set the number of threads in a Quartz.NET thread?

I saw in this section of the Quartz.NET documentation tutorial that it should be possible to determine the maximum number of threads the Quartz scheduler will use. In my special case, I want to set this number to 1. But in the API, I could not find a way to access the threadpool instance that my scheduler uses and set any properties on it.

Currently my code is as follows:

ISchedulerFactory schedFact = new StdSchedulerFactory(); IScheduler scheduler = schedFact.GetScheduler(); scheduler.Start(); // Setup jobs and triggers and then call scheduler.ScheduleJob... 

Does anyone know how I can set the number of threads in a pool?

Thanks for the help in advance!

+7
quartz-scheduler
source share
3 answers

It depends a little on the pool you are using and the configuration file that the scheduler is reading. But if you use the standard SimpleThreadPool.cs , then the number of threads can be configured inside the quartz.config file, 10 threads are created by default:

alt text

+2
source share

You can do this programmatically using the code below if you do not want to rely on the external quartz.config file for any reason:

  var properties = new NameValueCollection { {"quartz.threadPool.threadCount", "1"} }; var schedulerFactory = new StdSchedulerFactory(properties); var scheduler = schedulerFactory.GetScheduler(); 

I agree with the comments in the accepted answer, although in this case you will most likely want to use [DisallowConcurrentExecutionAttribute] in your IJob class.

+27
source share

In the web.config file, add the value below in the quartz section.

 <add key="quartz.threadPool.threadCount" value="20" /> 

The value represents the number of threads available for running tasks simultaneously.

+1
source share

All Articles