8

我在我的 quartz.properties 文件中设置了以下属性:

org.quartz.threadPool.threadCount = 60
org.quartz.scheduler.batchTriggerAcquisitionMaxCount = 60

,但是,由于某种原因,显然它没有生效。因为当我启动我的应用程序时,日志显示它仍然使用池中的 1 个线程:

[main] INFO org.quartz.impl.StdSchedulerFactory - Using default implementation for ThreadExecutor 
[main] INFO org.quartz.core.SchedulerSignalerImpl - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl 
[main] INFO org.quartz.core.QuartzScheduler - Quartz Scheduler v.2.1.1 created. 
[main] INFO org.quartz.simpl.RAMJobStore - RAMJobStore initialized.
[main] INFO org.quartz.core.QuartzScheduler - Scheduler meta-data: Quartz Scheduler (v2.1.1) 'QuartzScheduler' with instanceId 'NON_CLUSTERED' 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 1 threads.**

我知道,quartz.properties 需要在类路径中才能找到。我就这么做了。没有检测到此文件的任何其他原因?或者它被检测到但线程数设置不正确?

谢谢

4

3 回答 3

12

对于那些使用 Spring + Quartz 并且quartz.properties文件不工作的人(即在启动应用程序时被忽略):

org.quartz.Scheduler由 Spring Factory Bean ( ) 实例化的Quartz Scheduler ( ) 默认情况下org.springframework.scheduling.quartz.SchedulerFactoryBean不会quartz.properties从类路径中读取文件,正如 Quartz 文档中所说 - 您需要手动设置引用:

[在 Java 配置的情况下]:

@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    schedulerFactoryBean.setConfigLocation(new ClassPathResource("quartz.properties"));
    // ...
}

[在 XML 配置的情况下]:

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="configLocation" value="classpath:quartz.properties" />
    // ...
</bean>
于 2016-03-21T15:51:50.293 回答
4

哎呀,我发现了问题,实际上代码通过在代码中创建 Properties 类的实例来覆盖属性文件配置。所以答案是这一行:

sf = new StdSchedulerFactory("conf/quartz.properties");

于 2013-06-03T04:58:35.270 回答
2

如果有人仍在寻找答案,他们可以使用以下代码段

@Bean                                                                           
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
    scheduler.setTriggers(jobOneTrigger());
    scheduler.setQuartzProperties(quartzProperties());
    scheduler.setJobDetails(jobOneDetail());
    return scheduler;
}

@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
于 2019-11-19T08:19:07.473 回答