Skip to content

Commit

Permalink
Merge pull request #45195 from manofthepeace/quartz_customThreadPool
Browse files Browse the repository at this point in the history
Support custom thread pool in quartz
  • Loading branch information
gsmet authored Jan 7, 2025
2 parents 5b48946 + ca5dc93 commit 0e013fa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -216,7 +217,18 @@ List<ReflectiveClassBuildItem> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public class QuartzBuildTimeConfig {
@ConfigItem(defaultValue = "ram")
public StoreType storeType;

/**
* The class name of the thread pool implementation to use.
* <p>
* 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.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0e013fa

Please sign in to comment.