http://www.myexception.cn/h/988782.html

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-相关推荐

  1. 异常:“严重: The web application [] appears to have started a thread named [Thread-”

     严重: The web application [] appears to have started a thread named [TestScheduler_Worker-1] but ha ...

  2. The web application [] appears to have started a thread named [Thread-

    在eclipse上部署web项目到tomcat启动时出现了"The web application [] appears to have started a thread named [Th ...

  3. The web application [] appears to have started a thread named [thread-0]

    最近在项目中,突发了一个情况,就是服务器在跑了一段时间之后,总是会莫名其妙的挂掉,初始的时候认为是服务器原因,也没有多加理会,直接重启了服务,可是当这个情况出现了两三次之后,感觉不对,还是得解决一下, ...

  4. WebappClassLoaderBase | The web application [ROOT] appears to have started a thread named [HikariPo

    原文链接 linux(RHEL8)中使用root启动java程序(使用springboot 框架)时可以正常的访问,而当使用非root用户启动springboot 的java 程序时,遇到以下错误: ...

  5. tomcat 启动异常 The web application [ROOT] registered the JDBC driver [xxx] but failed to unregister it

    tomcat启动的时候出现如下异常: 22-Feb-2021 20:25:30.697 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina ...

  6. ModSecurity web application firewall (WAF) Research - .Little Hann

    转载地址:http://bluereader.org/article/97681813 catalog 引言 OWASP ModSecurity Core Rule Set (CRS) Project ...

  7. ModSecurity web application firewall (WAF) Research

    catalog 0. 引言1. OWASP ModSecurity Core Rule Set (CRS) Project2. Installation mod_security forApache3 ...

  8. 微软压力测试工具 web application stress

    WEB服务器的压力测试工具~ 115808 2009年8月1日 lbimba 铜牌会员 这里给广大的煤油推荐一个web网站压力测试工具.它可以用来模拟多个用户操作网站,在程序投入运行时,可以用它来进行 ...

  9. Unable to complete the scan for annotations for web application

    2019独角兽企业重金招聘Python工程师标准>>> Unable to complete the scan for annotations for web application ...

最新文章

  1. ssh隧道 学习总结
  2. AI:2021年WAIC世界人工智能大会2021年7月9日《可信AI论坛》、《AI引领探索保险科技新价值》、《产研共育·数智未来》等论坛演讲内容分享及解读
  3. HDU多校7 - 6850 Game(博弈+思维+贪心)
  4. 地铁看java书女生_地铁上背单词的女孩
  5. lvds单8转双8芯片_单片机定时芯片方案开发,2到8小时可调定时IC,低功耗触发延时芯片sop-8封装-丽晶微电子...
  6. 关于自然排序Comparable 和 比较器排序Comparator
  7. Keepalived-在没有之前配置的Nginx高可用(不建议采纳)
  8. 李煜东算法进阶指南打卡题解
  9. 办公利器:IBM Lotus Symphony轻松之旅
  10. Cookie的简单理解和使用
  11. 【货干】Idea 安装 MyBatis 插件
  12. ios跨线程通知_iOS通知线程处理 - osc_3m34anq6的个人空间 - OSCHINA - 中文开源技术交流社区...
  13. fiddler手机下载证书提示No root certificate was found. Have you enabled HTTPS traff 解决方法 及手机配置代理后无网络问题
  14. 微信开发者工作遇到的ERROR
  15. 160多个android开源代码汇总
  16. 电子计算机二级的模拟试题,计算机二级模拟试题
  17. 计算机价格谈判议程,价格谈判的几个小技巧
  18. 如何理解泰勒展开式,他有何用途?
  19. 基于Flexlive.CQP.Framework的C# 酷Q UDP实现
  20. BZOJ2407:探险/BZOJ4398:福慧双修-最短路+分治

热门文章

  1. android开发中磁场传感器,Android传感器(加速度传感器,磁场传感器,光线传感器,方向传感器)...
  2. 华为系统更新彻底卸载_华为手机系统更新好吗 华为手机系统更新方法
  3. 运行进入计算机服务,电脑怎么进入运行命令
  4. Mac安装truffle框架时出现✓ Preparing to download box ✖ Downloading Unbox failed! Error: connect的解决方法
  5. C++面试进阶之咖啡罐问题
  6. Eureka的InstanceInfoReplicator类(服务注册辅助工具)
  7. 【鼠标右键点击桌面图标时,出现资源管理器未响应】
  8. js生成8位随机字符串密码
  9. 解开关于人工智能的六个迷思
  10. 计算机软件基础自考实践报告,信息作战自考实践报告