设置石英线程池的线程数

时间:2017-04-20 08:08:58

标签: spring quartz-scheduler

我创建了文件quartz.properties并将其放在classpath中。 属性是

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.

是否加载属性或没有?无论如何我只为调度程序运行一个线程......

5 个答案:

答案 0 :(得分:1)

当我使用spring时,我确实喜欢这样。 我在公共properties文件中创建了一个属性

quartz.threadPool.threadCount=1

然后在我的xml中设置quartzProperties的字段ScheduleFactoryBean

<property name="quartzProperties">
    <util:properties>
        <prop key="org.quartz.threadPool.threadCount">
            ${quartz.threadPool.threadCount}
        </prop>
    </util:properties>
</property>

答案 1 :(得分:1)

@NikNik

org.quartz.threadPool.threadCount数据类型必须为String,因此应该为

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

...

StdSchedulerFactory factory = new StdSchedulerFactory(p);

答案 2 :(得分:0)

它可能没有加载您的属性文件。但是,为了避免使用属性,您可以使用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);

答案 3 :(得分:0)

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

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

答案 4 :(得分:0)

使用 Spring Boot 2.1.4,我能够使用以下属性设置线程池大小:

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