tomcat spring quartz =关机错误

我们正在努力做一件看起来非常简单的事情,但它不起作用,我在网上找到的解决方案似乎很复杂,因此我觉得我应该再问一遍 . 我们有一个在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 fials:

似乎已经启动了一个名为[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 -->

回答(1)

2 years ago

docs中,它显示:

如果使用org.quartz.ee.servlet.QuartzInitializerListener在servlet容器中启动调度程序,则在取消部署应用程序或应用程序服务器关闭时,其contextDestroyed()方法将关闭调度程序 .

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