How to solve quartz thread count must be > 0 exception?

1. The problem

Sometimes, we encounter this Exception when using quartz to schedule jobs.

org.quartz.SchedulerConfigException: Thread count must be > 0
at org.quartz.simpl.SimpleThreadPool.initialize(SimpleThreadPool.java:242) ~[quartz-2.2.1.jar:na]
at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1288) ~[quartz-2.2.1.jar:na]
at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1519) ~[quartz-2.2.1.jar:na]
at org.quartz.impl.StdSchedulerFactory.getDefaultScheduler(StdSchedulerFactory.java:1535) ~[quartz-2.2.1.jar:na]
at JobService.startJobs(JobService.java:230) [job-3.0.0-20180731-RELEASE.jar:na]
at JobService.reloadJobsByIntervalReally(JobService.java:191) [job-3.0.0-20180731-RELEASE.jar:na]
at JobService.lambda$reloadJobsByInterval$13(JobService.java:170) [job-x-RELEASE.jar:na]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_131]

2. Environments

  • JDK 1.8
  • Quartz 2.2.1
  • Springboot 1.5.9.RELEASE

3. The solution

  • According to MKYong.com post

    I searched the quartz.properties in the classpath, and I did find a quartz.properties, and delete it. But the issue still exist after restart.

  • Clear the classpath I found many backup jars in the root of the deploy dir, I delete the backup jars like this:

rm -rf myjob.jar.bak*
rm -rf myjob.exec.jar.bak*

At last, there is only one myjob.jar in the classpath, and the jar does not contain any quartz.properties in it. Restart the app, the problem disappeared.

3. Conclusion

To summarize: - There is no need for the quartz.properties file for most projects, If you find one, just delete it. - If you need the file, you can specify the content of the thread count properites like this:

org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin 
org.quartz.plugin.jobInitializer.fileNames = quartz-config.xml 
org.quartz.plugin.jobInitializer.failOnFileNotFound = true

If you don’t find any quartz.properties file in the classpath, check your jars, and make sure there are not any backup jars in the classpath