Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 设置石英线程池的线程计数_Spring_Quartz Scheduler - Fatal编程技术网

Spring 设置石英线程池的线程计数

Spring 设置石英线程池的线程计数,spring,quartz-scheduler,Spring,Quartz Scheduler,我已经创建了文件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. Cur

我已经创建了文件
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);
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {        
    SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
    Properties quartzProperties = new Properties();     
    quartzProperties.put("org.quartz.threadPool.threadCount", "1");
    scheduler.setQuartzProperties(quartzProperties);
    ...
    return scheduler;
}

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

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>

${quartz.threadPool.threadCount}

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

Properties p = new Properties();
p.put("org.quartz.scheduler.instanceName", "Scheduler_test");
p.put("org.quartz.threadPool.threadCount", 2);
...
StdSchedulerFactory factory = new StdSchedulerFactory(p);
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {        
    SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
    Properties quartzProperties = new Properties();     
    quartzProperties.put("org.quartz.threadPool.threadCount", "1");
    scheduler.setQuartzProperties(quartzProperties);
    ...
    return scheduler;
}
@尼克

org.quartz.threadPool.threadCount
数据类型必须是字符串,因此应该是

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


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


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

是的。的确虽然我使用了
属性
文件