How can I set the number of threads in the Quartz.NET threadpool?

岁酱吖の 提交于 2019-11-27 16:39:06

问题


I've seen in this tutorial section of the Quartz.NET documentation that it should be possible to define the maximum number of threads the Quartz scheduler is going to use. In my special case I want to set this number to 1. But in the API doc I couldn't find a way to access the threadpool instance my scheduler is using and to set any properties on it.

Currently my code looks like this:

ISchedulerFactory schedFact = new StdSchedulerFactory();

IScheduler scheduler = schedFact.GetScheduler();
scheduler.Start();

// Setup jobs and triggers and then call scheduler.ScheduleJob...

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

Thanks for help in advance!


回答1:


It depends a bit on the pool you're using and the config file the scheduler is reading. But if you are using the standard SimpleThreadPool.cs then the amount of threads can be configured inside the quartz.config file, by default 10 threads are created:




回答2:


You can do this programmatically with the code below if you don't want to rely on the external quartz.config file for whatever 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 though that in this case you probably want to use [DisallowConcurrentExecutionAttribute] on your IJob class instead.




回答3:


In the web.config file add below value under quartz section.

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

Value represents the number of threads that are available for concurrent execution of jobs.



来源:https://stackoverflow.com/questions/4108403/how-can-i-set-the-number-of-threads-in-the-quartz-net-threadpool

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!