java 如何确保使用了quartz.properties?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14707703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make sure quartz.properties is being used?
提问by mostafa.S
I set following properties in my quartz.properties file:
我在我的quartz.properties 文件中设置了以下属性:
org.quartz.threadPool.threadCount = 60
org.quartz.scheduler.batchTriggerAcquisitionMaxCount = 60
, however, for some reason, apparently it doesn't take effect. because when I start my application, the log shows that it still uses 1 thread in the pool:
但是,由于某种原因,显然它没有生效。因为当我启动我的应用程序时,日志显示它仍然使用池中的 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.**
I know, the quartz.properties needs to be at class path to be found. and I just did it. any other reason why this file is not detected? or it is detected but number of threads is not set correctly?
我知道,quartz.properties 需要在类路径中才能找到。我就是这么做的。未检测到此文件的任何其他原因?或者它被检测到但线程数设置不正确?
Thanks
谢谢
采纳答案by mostafa.S
oops, I found the problem, actually the code was overriding the properties file config by creating an instance of Properties class in the code. so the answer is this line:
哎呀,我发现了问题,实际上代码是通过在代码中创建 Properties 类的实例来覆盖属性文件配置的。所以答案是这一行:
sf = new StdSchedulerFactory("conf/quartz.properties");
sf = new StdSchedulerFactory("conf/quartz.properties");
回答by dominik
For those who are using Spring + Quartz and quartz.properties
file is not working (i.e. gets ignored while starting the application):
对于那些使用 Spring + Quartz 并且quartz.properties
文件不起作用的人(即在启动应用程序时被忽略):
Quartz Scheduler (org.quartz.Scheduler
) instantiated by Spring Factory Bean (org.springframework.scheduling.quartz.SchedulerFactoryBean
) won't read quartz.properties
file from the classpath by default as it's said in Quartz docs - you need to set the reference manually:
默认情况下,org.quartz.Scheduler
由 Spring Factory Bean ( ) 实例化的Quartz Scheduler ( )org.springframework.scheduling.quartz.SchedulerFactoryBean
不会quartz.properties
从类路径中读取文件,正如 Quartz 文档中所述 - 您需要手动设置引用:
[in case of Java config]:
[在 Java 配置的情况下]:
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setConfigLocation(new ClassPathResource("quartz.properties"));
// ...
}
[in case of XML config]:
[在 XML 配置的情况下]:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="configLocation" value="classpath:quartz.properties" />
// ...
</bean>
回答by Srikanth Josyula
If someone still looking for answer, they can use the below snippet
如果有人仍在寻找答案,他们可以使用以下代码段
@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();
}