The web application [] appears to have started ...

25 篇文章 1 订阅

 The web application [] appears to have started ...
  • 发布时间: 2012/07/25 11:51 
  • 阅读: 468 
  • 收藏: 0 
  • 点赞: 0 
  • 评论: 0

    有看到过这个标题的人吗?我的Tomcat出什么问题了?

    有一个servlet,它在init方法里面实例化了一个线程类。这个类里面启动了若干个daemon线程。

    有一个listener,它在contextDestroyed方法里面关闭这个线程类。

    在catalina.out里面出现了这样的日志。

    在下面的这个link里面,apache官方给了一些说明:

    http://wiki.apache.org/tomcat/MemoryLeakProtection

    其中就包含了这种问题。具体的原因说的很清楚:

    

 Here, when the app is stopped, the webapp classloader is still referenced by the spawned thread both through its context classloader and its current call stack (the anonymous Thread subclass is loaded by the webapp classloader). When stopping an application, tomcat checks the context classloader of every Thread, and if it is the same as the app being stopped, it logs the following message :  

    当前app的classloader的引用指向到里我的线程类。

    修改方法参照官方说明。

    

leakingThread.setContextClassLoader(null)

    还有另外一种修改方法。

    在我们的线程类里面加入stop方法: 

   

class Example implements Runnable {
        private volatile boolean isStop;
        private Thread runThread;

        @Override
        public void run() {
            runThread = Thread.currentThread();
            isStop = false;
            while(!isStop){
                try {
                    process();
                } catch (XMPPException e) {
                    log.error("Example logic exception.", e);
                }
            }
        }

        public void stopRun() {
        	isStop = true;
        	if(runThread != null) {
        		runThread.interrupt();
        	}
        }

    然后在contextDestroyed方法里面调用stopRun方法。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值