gpt4 book ai didi

spring - tomcat + spring + quartz = 关机错误

转载 作者:行者123 更新时间:2023-11-28 21:58:26 25 4
gpt4 key购买 nike

我们正在尝试做一件看起来非常简单的事情,但它不起作用,而且我在网上找到的解决方案对于如此基本的事情来说似乎很复杂,所以我觉得我应该再问一遍。我们有一个在 tomcat 下运行的 Spring Web 应用程序。我们向其中添加了 Quartz 调度程序:

<bean id="myScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="transactionManager" ref="myTransactionManager"/>

<property name="overwriteExistingJobs" value="true"/>

<property name="autoStartup" value="true"/>

<property name="jobFactory">
<bean class="AutowiringSpringBeanJobFactory"/>
</property>

<!-- NOTE: Must add both the jobDetail and trigger to the scheduler! -->
<property name="jobDetails">
<list>
<ref bean="jobDetailAutoSendPublishedReport" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTriggerAutoSendPublishedReport"/>
</list>
</property>

<property name="quartzProperties">
<props>
<!-- Main Scheduler Properties For A Clustered Scheduler -->
<prop key="org.quartz.scheduler.instanceName">test</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>
<prop key="org.quartz.scheduler.idleWaitTime">60000</prop>

<!-- ThreadPool -->
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">5</prop>

<!-- Shutdown Hook Plugin -->
<!--prop key="org.quartz.plugin.shutdownhook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
<prop key="org.quartz.plugin.shutdownhook.cleanShutdown">true</prop-->

<!-- JDBC JobStore -->
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.oracle.OracleDelegate</prop>
<prop key="org.quartz.jobStore.useProperties">false</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">300000</prop>
<prop key="org.quartz.jobStore.misfireThreshold">300000</prop>
</props>
</property>
</bean>

然后当我尝试关闭 tomcat 时,出现以下错误并且 tomcat 最终要关闭:

似乎启动了一个名为 [DefaultQuartzScheduler_QuartzSchedulerThread] 的线程,但未能停止它。这很可能造成内存泄漏。2015 年 1 月 27 日上午 1:09:35 org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks

我的解决方法是将以下内容添加到 web.xml 中:

 <!-- Start Quartz -->
<listener>
<listener-class>
org.quartz.ee.servlet.QuartzInitializerListener
</listener-class>
</listener>
<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>false</param-value> <!-- let spring handle starting -->
</context-param>
<!-- End of Quartz -->

最佳答案

docs上面写着:

If you are using the org.quartz.ee.servlet.QuartzInitializerListener to fire up a scheduler in your servlet container, its contextDestroyed() method will shutdown the scheduler when your application is undeployed or the application server shuts down.

也许你也可以添加这个监听器。

关于spring - tomcat + spring + quartz = 关机错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28164312/

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