tomcat + spring + quartz = 关机错误
tomcat + spring + quartz = shutdown error
我们正在尝试做一件看起来非常简单的事情,但它不起作用,而且我在网上找到的解决方案对于如此基本的东西来说似乎很复杂,所以我觉得我应该再问一遍。
我们在 tomcat 下有一个 Spring 网络应用程序 运行。我们向其中添加了 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.
也许你也可以添加这个监听器。
我们正在尝试做一件看起来非常简单的事情,但它不起作用,而且我在网上找到的解决方案对于如此基本的东西来说似乎很复杂,所以我觉得我应该再问一遍。 我们在 tomcat 下有一个 Spring 网络应用程序 运行。我们向其中添加了 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.
也许你也可以添加这个监听器。