严重: The web application [] appears to have started a thread named [Thread-
来源:互联网 发布:js动态添加a标签 编辑:程序博客网 时间:2024/04/30 12:21
严重: The web application [] appears to have started a thread named [Thread-
1,获取dump
2,从dump找到正在运行的线程所属class
3,在myeclise 开启debug模式,给正在运行的方法加上断点
4,这时你会发现当停止application时,有一个线程还没有停止掉
5,在 AppContextListener 进行contextDestroyed时,要加一段额外的代码,用来我们关闭tomcat的时候可以同时关闭此线程
例如此例:
在tomcat7+quartz1.8/1.7 + spring3.0.5做定时任务的时候 , 当关闭tomcat时抛异常"严重: The web application [] appears to have started a thread named [Thread-":
ar 27, 2013 6:05:35 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-nio-8082"]
Mar 27, 2013 6:05:35 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Mar 27, 2013 6:05:35 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/****] appears to have started a thread named [startQuertz_Worker-1] buthas failed to stop it. This is very likely to create a memory leak.
Mar 27, 2013 6:05:35 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/****] appears to have started a thread named [startQuertz_Worker-2] buthas failed to stop it. This is very likely to create a memory leak.
Mar 27, 2013 6:05:35 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/****] appears to have started a thread named [startQuertz_Worker-3] buthas failed to stop it. This is very likely to create a memory leak.
Mar 27, 2013 6:05:35 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
原因:tomcat在shutdown做清理工作的时候没能等待quartz完成cleanShutdown。就是tomcat太心急了,说 “quartz , 我关门了,你走吧!”,还没等quartz反应过来,就要关大门,这时发现 “quartz , 你怎么还在这儿呀!”。
解决办法:自己实现一个ServletContextListener,在contextDestroyed的时候主动调用quartz schedular的shutdown方法,并且主线程sleep一会儿.
代码:
public class QuartzContextListener implements ServletContextListener {
/*
* 测试代码写得随便
*
* @seejavax.servlet.ServletContextListener#contextDestroyed(javax.servlet.
* ServletContextEvent)
*/
@Override
public void contextDestroyed(ServletContextEvent arg0) {
WebApplicationContext webApplicationContext = (WebApplicationContext) arg0
.getServletContext()
.getAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
org.quartz.impl.StdScheduler startQuertz = (org.quartz.impl.StdScheduler) webApplicationContext
.getBean("startQuertz");
if(startQuertz != null) {
startQuertz.shutdown();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
/*
* (non-Javadoc)
*
* @see
* javax.servlet.ServletContextListener#contextInitialized(javax.servlet
* .ServletContextEvent)
*/
@Override
public void contextInitialized(ServletContextEvent arg0) {
<span style="white-space:pre"> </span>//不做任何事情
}
}
最后在 web.xml 配置QuartzContextListener。
注意:如果tomcat在Dameon模式下,以上方法不起作用,请参考:
http://wiki.apache.org/tomcat/MemoryLeakProtection
- 异常:“严重: The web application [] appears to have started a thread named [Thread-”
- 严重: The web application [] appears to have started a thread named [Thread-
- 严重:The web application [web01] appears to have started a thread named ...
- The web application [] appears to have started a thread named [Thread-
- The web application [/jenkins] appears to have started a thread named [Executor [问题点数:20分]
- 关闭Tomcat报错The web application [ROOT] appears to have started a thread named [Abandoned connectio
- Tomcat 报错:The web application [XXX] appears to have started a thread...
- The web application [] appears to have started ...
- tomcat-quartz appears to have started a thread named [startQuertz_Worker-1] but has failed to stop i
- appears to have started a thread named [startQuertz_xxx] but has failed to stop it. This is very...
- Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be
- Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be
- How to have a native thread in java
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- "This application is modifying the autolayout engine from a background thread, which can lead to en
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- CTS 源码分析(一)--CTS概况
- Emeditor ,果然很强大!
- String StringBuffer和StringBuilder异同
- QT5中文显示乱码解决方法
- 支付系统开发--简易版支付系统部署(单节点)
- 严重: The web application [] appears to have started a thread named [Thread-
- HDFS Shell 命令
- PHP购物车原理
- iOS开发--FMDB的使用
- 使用CHyperLink类为静态文本添加超链接的方法
- Liunx配置网络到nginx环境搭建步骤
- obj 转Json 保留空值字段
- eclipse快捷键整理
- jQuery中的$.grep()方法的使用