gpt4 book ai didi

quartz-scheduler - web.xml 中的 Quartz 属性文件配置及其位置

转载 作者:行者123 更新时间:2023-12-04 18:10:19 25 4
gpt4 key购买 nike

我试图解决避免长时间加载默认 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的官方文档为quartz.properties文件设置不同的路径:QuartzInitializerListner .例如:

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

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

最佳答案

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

你的上下文参数应该是这样的:

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

看看 quartz 的代码:

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

其中 filename 是属性文件。

因此,它尝试将文件作为流获取。请检查 Java 文档:

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

...玩得开心

关于quartz-scheduler - web.xml 中的 Quartz 属性文件配置及其位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14934825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com