2013-02-18 95 views
2

我试图解决避免长时间加载默认quartz.properties文件的问题。希望有人能在这里举手。非常感谢!web.xml中的Quartz属性文件配置及其位置

基本上,我已经阅读了许多关于这个问题的文章,而他们的解决方案并没有解决我的问题。我已经把quartz.properties WEB-INF/classes目录下的文件,并使用上下文侦听以下是我在web.xml配置:

<context-param> 
    <param-name>quartz:config-file</param-name> 
    <param-value>quartz.properties</param-value> 
</context-param> 

<context-param> 
    <param-name>quartz:shutdown-on-unload</param-name> 
    <param-value>true</param-value> 
</context-param> 

<context-param> 
    <param-name>quartz:wait-on-shutdown</param-name> 
    <param-value>true</param-value> 
</context-param> 

<context-param> 
    <param-name>quartz:start-on-load</param-name> 
    <param-value>true</param-value> 
</context-param> 

<listener> 
    <listener-class> 
     org.quartz.ee.servlet.QuartzInitializerListener 
    </listener-class> 
</listener> 

结果仍然显示是这样的:

[INFO] 18 Feb 06:37:29.218 PM main [org.quartz.impl.StdSchedulerFactory] 
Using default implementation for ThreadExecutor 

[INFO] 18 Feb 06:37:29.265 PM main [org.quartz.core.SchedulerSignalerImpl] 
Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl 

[INFO] 18 Feb 06:37:29.265 PM main [org.quartz.core.QuartzScheduler] 
Quartz Scheduler v.2.1.6 created. 

[INFO] 18 Feb 06:37:29.265 PM main [org.quartz.simpl.RAMJobStore] 
RAMJobStore initialized. 

[INFO] 18 Feb 06:37:29.281 PM main [org.quartz.core.QuartzScheduler] 
Scheduler meta-data: Quartz Scheduler (v2.1.6) 'MyQuartzTest' 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 12 threads. 
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered. 

[INFO] 18 Feb 06:37:29.281 PM main [org.quartz.impl.StdSchedulerFactory] 
Quartz scheduler 'MyQuartzTest' initialized from default resource file in Quartz package: 'quartz.properties' 

[INFO] 18 Feb 06:37:29.281 PM main [org.quartz.impl.StdSchedulerFactory] 
Quartz scheduler version: 2.1.6 

[INFO] 18 Feb 06:37:29.281 PM main [org.quartz.core.QuartzScheduler] 
Scheduler MyQuartzTest_$_NON_CLUSTERED started. 

[INFO] 18 Feb 06:37:29.312 PM MyQuartzTest_Worker-1 [org.quartz.examples.example1.HelloJob] 
Hello World! - Mon Feb 18 18:37:29 GMT+08:00 2013 

[INFO] 18 Feb 06:38:09.296 PM MyQuartzTest_Worker-2 [org.quartz.examples.example1.HelloJob] 
Hello World! - Mon Feb 18 18:38:09 GMT+08:00 2013 

[INFO] 18 Feb 06:38:29.296 PM main [org.quartz.core.QuartzScheduler] 
Scheduler MyQuartzTest_$_NON_CLUSTERED shutting down. 

[INFO] 18 Feb 06:38:29.296 PM main [org.quartz.core.QuartzScheduler] 
Scheduler MyQuartzTest_$_NON_CLUSTERED paused. 

[INFO] 18 Feb 06:38:29.296 PM main [org.quartz.core.QuartzScheduler] 
Scheduler MyQuartzTest_$_NON_CLUSTERED shutdown complete. 

另一个迷惑我有,如果它真的加载了默认的quartz.properties文件,那么为什么线程池和调度程序名称是根据我的自定义quartz.properties文件正确设置的?

另一方面,我也试着根据Quartz的官方文档设置quartz.properties文件的不同路径:QuartzInitializerListner。例如:

<context-param> 
    <param-name>quartz:config-file</param-name> 
    <param-value>/MyProject/WEB-INF/my_quartz.properties</param-value> 
</context-param> 

结果显示更糟。这将完全是默认设置。因此,我现在很迷茫。请详细说明这种情况的根本原因。非常感谢你!

回答

0

我解决了这个问题,将 quartz.properties放在我的资源文件夹(src/main/resources)中。

你的背景下帕拉姆应该是这样的:

<context-param> 
    <param-name>quartz:config-file</param-name> 
    <param-value>quartz.properties</param-value> 
</context-param> 

看看石英代码:

InputStream is = null; 
Properties props = new Properties(); 
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename); 

其中是属性文件。

因此,它会尝试将文件作为Stream。请检查Java文档:

https://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html

...有乐趣