diff --git a/extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/QuartzProcessor.java b/extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/QuartzProcessor.java index 9c6dfe0f27814..4eeb4c4e1bbd5 100644 --- a/extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/QuartzProcessor.java +++ b/extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/QuartzProcessor.java @@ -34,6 +34,7 @@ import org.quartz.simpl.SimpleThreadPool; import org.quartz.spi.InstanceIdGenerator; import org.quartz.spi.SchedulerPlugin; +import org.quartz.spi.ThreadPool; import org.quartz.utils.DirtyFlagMap; import org.quartz.utils.StringKeyDirtyFlagMap; @@ -216,7 +217,18 @@ List reflectiveClasses(QuartzBuildTimeConfig config, .serialization(true).build()); } - reflectiveClasses.add(ReflectiveClassBuildItem.builder(SimpleThreadPool.class, SimpleInstanceIdGenerator.class) + Class threadPoolClass; + try { + threadPoolClass = Class.forName(config.threadPoolClass, false, Thread.currentThread().getContextClassLoader()); + if (!ThreadPool.class.isAssignableFrom(threadPoolClass)) { + throw new ConfigurationException( + "Thread pool class does not implement ThreadPool interface spi: " + config.threadPoolClass); + } + } catch (ClassNotFoundException e) { + throw new ConfigurationException("Thread pool class not found: " + config.threadPoolClass); + } + + reflectiveClasses.add(ReflectiveClassBuildItem.builder(threadPoolClass, SimpleInstanceIdGenerator.class) .reason(getClass().getName()) .methods().build()); reflectiveClasses diff --git a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzBuildTimeConfig.java b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzBuildTimeConfig.java index 0126024e34cb9..ba503b3711d25 100644 --- a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzBuildTimeConfig.java +++ b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzBuildTimeConfig.java @@ -42,6 +42,15 @@ public class QuartzBuildTimeConfig { @ConfigItem(defaultValue = "ram") public StoreType storeType; + /** + * The class name of the thread pool implementation to use. + *

+ * It's important to bear in mind that Quartz threads are not used to execute scheduled methods, instead the regular Quarkus + * thread pool is used by default. See also {@code quarkus.quartz.run-blocking-scheduled-method-on-quartz-thread}. + */ + @ConfigItem(defaultValue = "org.quartz.simpl.SimpleThreadPool") + public String threadPoolClass; + /** * The name of the datasource to use. *

diff --git a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSchedulerImpl.java b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSchedulerImpl.java index a231c29e65b61..1d1422912da9a 100644 --- a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSchedulerImpl.java +++ b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSchedulerImpl.java @@ -579,7 +579,7 @@ private Properties getSchedulerConfigurationProperties(QuartzSupport quartzSuppo props.put(StdSchedulerFactory.PROP_SCHED_MAX_BATCH_SIZE, "" + runtimeConfig.batchTriggerAcquisitionMaxCount); props.put(StdSchedulerFactory.PROP_SCHED_WRAP_JOB_IN_USER_TX, "false"); props.put(StdSchedulerFactory.PROP_SCHED_SCHEDULER_THREADS_INHERIT_CONTEXT_CLASS_LOADER_OF_INITIALIZING_THREAD, "true"); - props.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, "org.quartz.simpl.SimpleThreadPool"); + props.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, buildTimeConfig.threadPoolClass); props.put(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS, InitThreadContextClassLoadHelper.class.getName()); props.put(StdSchedulerFactory.PROP_THREAD_POOL_PREFIX + ".threadCount", "" + runtimeConfig.threadCount); props.put(StdSchedulerFactory.PROP_THREAD_POOL_PREFIX + ".threadPriority", "" + runtimeConfig.threadPriority);