我在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需要在类路径上才能找到。我就这么做了。没有检测到该文件的任何其他原因?或者它被检测到但线程数没有正确设置?
感谢
对于那些使用Spring+Quartz且quartz.properties
文件不起作用(即在启动应用程序时被忽略)的用户:
Spring Factory Bean(org.springframework.scheduling.quartz.SchedulerFactoryBean
)实例化的Quartz Scheduler(org.quartz.Scheduler
)默认不会像Quartz文档中所说的那样从类路径读取quartz.properties
文件-您需要手动设置引用:
[在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>
oops,我发现了这个问题,实际上代码通过在代码中创建properties class的实例来覆盖属性文件配置。所以答案是这样的:
sf = new StdSchedulerFactory("conf/quartz.properties");
如果有人仍在寻找答案,他们可以使用下面的片段
@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();
}
如果以前的解决方案不适合您,请将属性文件移动到项目的/resource目录中。然后,您的配置将在默认情况下被选中。