设置石英线程池的线程数

set thread count for quartz thread pool

我创建了文件 quartz.properties 并将其放入类路径中。 属性是

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 1

但是当我启动应用程序时,我收到这条消息

Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

它加载 属性 还是不加载?我 运行 调度程序只有一个线程...

它可能没有加载您的属性文件。但是,为了避免使用属性,您可以使用 java 配置来配置调度程序:

Properties p = new Properties();
p.put("org.quartz.scheduler.instanceName", "Scheduler_test");
p.put("org.quartz.threadPool.threadCount", 2);
...
StdSchedulerFactory factory = new StdSchedulerFactory(p);

因为我正在使用 spring 我喜欢这个。 我在我的公共 properties 文件中创建了一个 属性

quartz.threadPool.threadCount=1

然后在我的xml

中设置ScheduleFactoryBean的字段quartzProperties
<property name="quartzProperties">
    <util:properties>
        <prop key="org.quartz.threadPool.threadCount">
            ${quartz.threadPool.threadCount}
        </prop>
    </util:properties>
</property>

如果您使用带注释的 Spring 配置:

@Bean
public SchedulerFactoryBean schedulerFactoryBean() {        
    SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
    Properties quartzProperties = new Properties();     
    quartzProperties.put("org.quartz.threadPool.threadCount", "1");
    scheduler.setQuartzProperties(quartzProperties);
    ...
    return scheduler;
}

@NikNik

org.quartz.threadPool.threadCount 数据类型必须是字符串,所以它应该是

p.put("org.quartz.threadPool.threadCount", "2");

...

StdSchedulerFactory factory = new StdSchedulerFactory(p);

使用 Spring Boot 2.1.4 我可以使用以下 属性:

设置线程池大小

spring.quartz.properties.org.quartz.threadPool.threadCount=2