Pages

Thursday 26 April 2012

How to set the Thread Pool Size in Quartz.Net?

By default Quartz.net creates a pool with 10 threads. How to change the size of the pool?

This is not obvious from the documentation, but burried inside one of the examples that come with the library:

            NameValueCollection properties = new NameValueCollection();
            properties["quartz.threadPool.threadCount"] = "1";

            ISchedulerFactory sf = new StdSchedulerFactory(properties);
            IScheduler sched = sf.GetScheduler();

 

Why did I need to change the pool size to 1? Well my jobs are executing third-party .NET wrappers around some native code that is not exactly thread-safe. I had a situation where I couldn’t schedule the same job twice: on first execution the job would run fine on thread 1. On second execution the same job would start on thread 2 then hang on a 3rd party method call. Forcing both runs to happen on the same thread fixed the problem.

Tutorial:

http://quartznet.sourceforge.net/tutorial/lesson_10.html

API Documentation

http://quartznet.sourceforge.net/apidoc/2.0/html/webframe.html