quartzScheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak解决

来源:互联网 发布:柴静去哪儿了 知乎 编辑:程序博客网 时间:2024/04/28 19:13

出现此问题是由一于spring 启动了quartz,而当tomcat 关闭的时候而没有关闭造成的。

在web 加一个监听器当关系的时候判断作业是否启动,启动就关闭。

<!-- 作业监听器 -->
 <listener>
   <listener-class>cn.test.job.JobListener</listener-class>
 </listener>

 

 

public class JobListener implements ServletContextListener {

 public void contextDestroyed(ServletContextEvent arg0) {
  Scheduler job = (Scheduler) SpringBeanLoader.getSpringBean("quartzScheduler");
  try {
   if(job.isStarted()){
    job.shutdown();
    Thread.sleep(1000);
   }
  } catch (SchedulerException e) {
   e.printStackTrace();
  } catch (InterruptedException e) {
   e.printStackTrace();
  }

 }

 public void contextInitialized(ServletContextEvent arg0) {
  

 }

 加 上过后会有此显示,创建的10个线程就会被关闭。如果Thread.sleep(1000)如果不会有些线程不会关闭。不知道有什么更好方法不。

2012-03-15 10:56:10,063 DEBUG [quartzScheduler_Worker-4] - WorkerThread is shutting down
2012-03-15 10:56:10,073 DEBUG [quartzScheduler_Worker-7] - WorkerThread is shutting down
2012-03-15 10:56:10,083 DEBUG [quartzScheduler_Worker-9] - WorkerThread is shutting down

 

严重: The web application [/blazeds] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@510530ae]) and a value of type [flex.messaging.io.SerializationContext] (value [flex.messaging.io.SerializationContext@2bbf1910]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
三月 01, 2012 1:34:31 下午 org.apache.catalina.core.ApplicationContext log
信息: Destroying Spring FrameworkServlet 'httpinvokerServlet'
三月 01, 2012 1:34:32 下午 org.apache.catalina.core.ApplicationContext log
信息: Destroying Spring FrameworkServlet 'hessianServlet'
三月 01, 2012 1:34:32 下午 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/xxx] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-2] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-3] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-4] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-5] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-6] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-7] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-8] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-9] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_Worker-10] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [QuartzScheduler_DefaultQuartzScheduler-HEPENG-PC1330573367454_ClusterManager] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [QuartzScheduler_DefaultQuartzScheduler-HEPENG-PC1330573367454_MisfireHandler] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xxx] appears to have started a thread named [DefaultQuartzScheduler_QuartzSchedulerThread] but has failed to stop it. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
严重: The web application [/xxx] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@6c4d554a]) and a value of type [flex.messaging.io.SerializationContext] (value [flex.messaging.io.SerializationContext@491aa4d2]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
三月 01, 2012 1:34:32 下午 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
严重: The web application [/xxx] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@743afc7c]) and a value of type [com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil.FactorySettings] (value [com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil$FactorySettings@4c966c81]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
三月 01, 2012 1:34:33 下午 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextDestroyed()
三月 01, 2012 1:34:33 下午 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextDestroyed()
三月 01, 2012 1:34:33 下午 org.apache.coyote.http11.Http11AprProtocol destroy
信息: Stopping Coyote HTTP/1.1 on http-8080
三月 01, 2012 1:34:33 下午 org.apache.coyote.ajp.AjpAprProtocol destroy
信息: Stopping Coyote AJP/1.3 on ajp-8009
三月 01, 2012 1:34:43 下午 org.slf4j.impl.JDK14LoggerAdapter fillCallerData
严重: An error occured while scanning for the next trigger to fire.
org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'springNonTxDataSource.DefaultQuartzScheduler': java.lang.NullPointerException [See nested exception: java.lang.NullPointerException]
 at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:170)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3785)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2753)
 at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:263)
Caused by: java.lang.NullPointerException
 at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:162)
 ... 3 more
三月 01, 2012 1:34:48 下午 org.slf4j.impl.JDK14LoggerAdapter fillCallerData
严重: MisfireHandler: Error handling misfires: Failed to obtain DB connection from data source 'springNonTxDataSource.DefaultQuartzScheduler': java.lang.NullPointerException
org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'springNonTxDataSource.DefaultQuartzScheduler': java.lang.NullPointerException [See nested exception: java.lang.NullPointerException]
 at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:170)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.doRecoverMisfires(JobStoreSupport.java:3132)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport$MisfireHandler.manage(JobStoreSupport.java:3923)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport$MisfireHandler.run(JobStoreSupport.java:3943)
Caused by: java.lang.NullPointerException
 at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:162)
 ... 3 more
三月 01, 2012 1:34:49 下午 org.slf4j.impl.JDK14LoggerAdapter fillCallerData
严重: ClusterManager: Error managing cluster: Failed to obtain DB connection from data source 'springNonTxDataSource.DefaultQuartzScheduler': java.lang.NullPointerException
org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'springNonTxDataSource.DefaultQuartzScheduler': java.lang.NullPointerException [See nested exception: java.lang.NullPointerException]
 at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:170)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.doCheckin(JobStoreSupport.java:3208)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3847)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.run(JobStoreSupport.java:3883)
Caused by: java.lang.NullPointerException
 at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:162)
 ... 3 more

 

加上过后再停止tomcat 就会显示相应线程就会关闭。

2012-03-15 10:56:10,063 DEBUG [quartzScheduler_Worker-4] - WorkerThread is shutting down
2012-03-15 10:56:10,073 DEBUG [quartzScheduler_Worker-7] - WorkerThread is shutting down
2012-03-15 10:56:10,083 DEBUG [quartzScheduler_Worker-9] - WorkerThread is shutting down
2012-03-15 10:56:10,104 DEBUG [quartzScheduler_Worker-2] - WorkerThread is shutting down
2012-03-15 10:56:10,104 DEBUG [quartzScheduler_Worker-1] - WorkerThread is shutting down
2012-03-15 10:56:10,104 DEBUG [quartzScheduler_Worker-5] - WorkerThread is shutting down
2012-03-15 10:56:10,144 DEBUG [quartzScheduler_Worker-8] - WorkerThread is shutting down
2012-03-15 10:56:10,184 DEBUG [quartzScheduler_Worker-3] - WorkerThread is shutting down
2012-03-15 10:56:10,184 DEBUG [quartzScheduler_Worker-10] - WorkerThread is shutting down


2012-03-15 10:56:10,063 DEBUG [quartzScheduler_Worker-4] - WorkerThread is shutting down
2012-03-15 10:56:10,073 DEBUG [quartzScheduler_Worker-7] - WorkerThread is shutting down
2012-03-15 10:56:10,083 DEBUG [quartzScheduler_Worker-9] - WorkerThread is shutting down
2012-03-15 10:56:10,104 DEBUG [quartzScheduler_Worker-2] - WorkerThread is shutting down
2012-03-15 10:56:10,104 DEBUG [quartzScheduler_Worker-1] - WorkerThread is shutting down
2012-03-15 10:56:10,104 DEBUG [quartzScheduler_Worker-5] - WorkerThread is shutting down
2012-03-15 10:56:10,144 DEBUG [quartzScheduler_Worker-8] - WorkerThread is shutting down
2012-03-15 10:56:10,184 DEBUG [quartzScheduler_Worker-3] - WorkerThread is shutting down
2012-03-15 10:56:10,184 DEBUG [quartzScheduler_Worker-10] - WorkerThread is shutting down

原创粉丝点击