严重: The web application [] appears to have started a thread named [Thread-

25 篇文章 1 订阅

严重: The web application [] appears to have started a thread named [Thread-

www.MyException.Cn  网友分享于:2015-02-04   搜索量:2572次
width="300" height="250" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_0" name="aswift_0" style="margin: 0px; padding: 0px; left: 0px; position: absolute; top: 0px;">
id="iframeu1107459_0" src="http://pos.baidu.com/iccm?rdid=1107459&dc=2&di=u1107459&dri=0&dis=0&dai=3&ps=263x502&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1466406740139&ti=%E4%B8%A5%E9%87%8D%3A%20The%20web%20application%20%5B%5D%20appears%20to%20have%20started%20a%20thread%20&ari=1&dbv=2&drs=1&pcs=1293x551&pss=1293x527&cfv=0&cpl=4&chi=1&cce=true&cec=UTF-8&tlm=1430680323&ltu=http%3A%2F%2Fwww.myexception.cn%2Fh%2F988782.html&ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DVuJENSw-xov8qLLOzuDBjOeD969YRPV-vlhqU12WxJd-vj_W_1TbuhFDFgaOcHmNCpELIdx2eW0374AUsQziEq%26wd%3D%26eqid%3Db404a01e00008c900000000357679853&ecd=1&psr=1366x768&par=1366x728&pis=-1x-1&ccd=24&cja=true&cmi=6&col=zh-CN&cdo=-1&tcn=1466406740&qn=80377c0e5e90c4b2&tt=1466406740119.331.427.433" width="300" height="250" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="margin: 0px; padding: 0px; border-width: 0px; border-style: initial; vertical-align: bottom;">

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


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Web应用程序 [root] 看上去启动了一个名为 [rxiosched] 的线程。根据描述,[rxiosched] 可能是一个与 RxJava 相关的调度器,用于管理响应式编程任务的线程调度。 RxJava 是一个用于构建基于事件流与数据流的异步和基于事件驱动的程序库,常用于开发响应式的Android应用。在RxJava中,任务可以通过不同的调度器在后台线程中运行,以避免阻塞主线程并提高应用程序的性能和响应性。 通过 [root] 应用程序启动了 [rxiosched] 线程,可能表明该应用程序正在使用RxJava库,并使用该调度器来处理异步任务。这可能意味着应用程序正在通过订阅观察者模式来处理事件,使任务在合适的时间和线程上执行。 这种线程调度的方法可以确保主线程不会被阻塞,这在开发需要进行网络请求或耗时操作的应用程序时尤为重要。它可以提供更好的用户体验,因为应用程序可以同时执行多个任务,并在数据准备好后及时响应用户输入。 就线程名称来说,[rxiosched] 或许是为了特定目的而命名的,我无法准确判断。但根据常规命名习惯,它可能与 RxJava 的 IO 调度器相关,用于在应用程序进行IO操作时进行线程调度。 总之,[root] 应用程序启动了 [rxiosched] 线程,这可能意味着应用程序正在使用RxJava库进行响应式编程,并使用调度器来管理任务线程。这种方法有助于提高应用程序的性能和响应性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值