我在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需要在类路径中找到。而我刚刚做到了 为什么没有检测到这个文件的任何其他原因?或检测到但线程数未正确设置?
由于
答案 0 :(得分:7)
对于那些使用Spring + Quartz并且quartz.properties
文件不起作用的人(即在启动应用程序时被忽略):
由Spring Factory Bean(org.quartz.Scheduler
)实例化的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>
答案 1 :(得分:1)
sf = new StdSchedulerFactory("conf/quartz.properties");
答案 2 :(得分:0)
如果有人仍在寻找答案,他们可以使用以下代码段
@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();
}