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

标签 spring tomcat quartz-scheduler

我们正在尝试做一件看似非常简单的事情,但它不起作用,而且我在网上找到的解决方案对于如此基本的事情似乎很复杂,所以我觉得我应该再问一次。 我们有一个在 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/

相关文章:

java - Spring ClientInterceptor 在响应中显示空的 SOAP header

Spring第一次请求非常慢

java - Spring Autowiring 不起作用

spring - 将 Spring Quartz 与 JDBC Store 结合使用时的依赖注入(inject)

java - Quartz 调度程序作业未存储在数据库中

java - 如何在所有 'workers' 上安排 quartz 作业?

multithreading - 使用 Spring 批处理文件项阅读器进行多线程处理

java - HBase on Tomcat7 安装错误: Could not initialize class org. apache.hadoop.security.ShellBasedUnixGroupsMapping

java - 在应用程序运行的前 5 个小时内,每 2 分钟执行一次 Tomcat 完整 GC

java - 获取我的项目文件夹的路径