我试图解决避免长时间加载默认quartz.properties文件的问题。希望有人能在这里伸出援助之手。非常感谢!
基本上,我已经阅读了很多关于这个问题的帖子,而他们的解决方案并没有解决我的问题。我已将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的官方文档QuartzInitializerListner为quartz.properties文件设置不同的路径。例如:
<context-param>
<param-name>quartz:config-file</param-name>
<param-value>/MyProject/WEB-INF/my_quartz.properties</param-value>
</context-param>
结果显示更糟糕。这将是完全默认的设置。因此,我现在很迷茫。请详细说明这种情况的根本原因。非常感谢你!
答案 0 :(得分:1)
我修复了这个问题,将 quartz.properties 放在我的资源文件夹(src / main / resources)中。
您的上下文Param应如下所示:
<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);
其中 filename 是属性文件。
因此,它尝试将文件作为Stream。请查看Java Doc:
https://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html
......玩得开心