{"action":"created","issue":{"url":"https://api.github.com/repos/dangdangdotcom/dubbox/issues/58","repository_url":"https://api.github.com/repos/dangdangdotcom/dubbox","labels_url":"https://api.github.com/repos/dangdangdotcom/dubbox/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/dangdangdotcom/dubbox/issues/58/comments","events_url":"https://api.github.com/repos/dangdangdotcom/dubbox/issues/58/events","html_url":"https://github.com/dangdangdotcom/dubbox/issues/58","id":112786799,"number":58,"title":"dubbox在tomcat容器中使用，shutdown关闭的时候JVM无法结束","user":{"login":"deepshrift","id":3361754,"avatar_url":"https://avatars.githubusercontent.com/u/3361754?v=3","gravatar_id":"","url":"https://api.github.com/users/deepshrift","html_url":"https://github.com/deepshrift","followers_url":"https://api.github.com/users/deepshrift/followers","following_url":"https://api.github.com/users/deepshrift/following{/other_user}","gists_url":"https://api.github.com/users/deepshrift/gists{/gist_id}","starred_url":"https://api.github.com/users/deepshrift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deepshrift/subscriptions","organizations_url":"https://api.github.com/users/deepshrift/orgs","repos_url":"https://api.github.com/users/deepshrift/repos","events_url":"https://api.github.com/users/deepshrift/events{/privacy}","received_events_url":"https://api.github.com/users/deepshrift/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-10-22T11:51:19Z","updated_at":"2016-04-15T06:07:38Z","closed_at":null,"body":"dubbox 8月份拉取的最新版本。JDK7下构建。\r\n运行环境是  tomcat8+JDK8\r\n程序使用JDK8开发，编译级别JDK7\r\n问题对我们困扰非常大，还请高手们帮忙分析下，多谢啦！\r\n\r\n在执行tomcat的shutdown后，日志中出现很多memoryleak的错误，JVM无法结束。 按照https://github.com/alibaba/dubbo/issues/95 的建议，加入了ApplicationListener<ContextClosedEvent>执行ProtocolConfig.destroyAll()。 dubbo服务提供者端的tomcat可以正常关闭，但是dubbo 消费者端tomcat关闭后jvm进程仍然在。\r\n经过观察，凡是JVM进程不能结束，tomcat日志有如下错误：\r\n22-Oct-2015 19:38:39.178 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [wx-business] created a ThreadLocal with key of type [com.alibaba.dubbo.rpc.RpcContext$1] (value [com.alibaba.dubbo.rpc.RpcContext$1@3fcbc3da]) and a value of type [com.alibaba.dubbo.rpc.RpcContext] (value [com.alibaba.dubbo.rpc.RpcContext@1f4bdee]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.\r\n22-Oct-2015 19:38:39.196 INFO [localhost-startStop-1-SendThread(10.135.100.231:2181)] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load [org.apache.zookeeper.server.ZooTrace]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.\r\n java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.apache.zookeeper.server.ZooTrace]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1335)\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1321)\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1203)\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1164)\r\n        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1128)\r\n\r\n22-Oct-2015 19:38:39.200 INFO [localhost-startStop-1-SendThread(10.135.100.231:2181)] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load [org.apache.logging.log4j.core.impl.ThrowableProxy]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.\r\n java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.apache.logging.log4j.core.impl.ThrowableProxy]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1335)\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1321)\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1203)\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1164)\r\n        at org.apache.logging.log4j.core.impl.Log4jLogEvent.getThrownProxy(Log4jLogEvent.java:323)\r\n        at org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter.format(ExtendedThrowablePatternConverter.java:64)\r\n        at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:36)\r\n        at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:196)\r\n        at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:55)\r\n        at org.apache.logging.log4j.core.layout.AbstractStringLayout.toByteArray(AbstractStringLayout.java:71)\r\n        at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:108)\r\n        at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:99)\r\n        at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:430)\r\n        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:409)\r\n        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:412)\r\n        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:367)\r\n        at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:112)\r\n        at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:727)\r\n        at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:716)\r\n        at org.apache.logging.slf4j.Log4jLogger.error(Log4jLogger.java:318)\r\n        at org.apache.zookeeper.ClientCnxn$1.uncaughtException(ClientCnxn.java:414)\r\n        at java.lang.Thread.dispatchUncaughtException(Thread.java:1952)\r\n\r\n22-Oct-2015 19:38:39.206 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler [\"http-nio-18080\"]\r\n2015-10-22 19:38:39,202 ERROR An exception occurred processing Appender Console java.lang.IllegalStateException: Can't overwrite cause with java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.apache.logging.log4j.core.impl.ThrowableProxy]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.\r\n        at java.lang.Throwable.initCause(Throwable.java:457)\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1324)\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1203)\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1164)\r\n        at org.apache.logging.log4j.core.impl.Log4jLogEvent.getThrownProxy(Log4jLogEvent.java:323)\r\n        at org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter.format(ExtendedThrowablePatternConverter.java:64)\r\n        at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:36)\r\n        at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:196)\r\n        at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:55)\r\n        at org.apache.logging.log4j.core.layout.AbstractStringLayout.toByteArray(AbstractStringLayout.java:71)\r\n        at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:108)\r\n        at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:99)\r\n        at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:430)\r\n        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:409)\r\n        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:412)\r\n        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:367)\r\n        at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:112)\r\n        at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:727)\r\n        at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:716)\r\n        at org.apache.logging.slf4j.Log4jLogger.error(Log4jLogger.java:318)\r\n        at org.apache.zookeeper.ClientCnxn$1.uncaughtException(ClientCnxn.java:414)\r\n        at java.lang.Thread.dispatchUncaughtException(Thread.java:1952)\r\nCaused by: java.lang.ClassNotFoundException\r\n        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1323)\r\n        ... 20 more\r\n"},"comment":{"url":"https://api.github.com/repos/dangdangdotcom/dubbox/issues/comments/210300020","html_url":"https://github.com/dangdangdotcom/dubbox/issues/58#issuecomment-210300020","issue_url":"https://api.github.com/repos/dangdangdotcom/dubbox/issues/58","id":210300020,"user":{"login":"StonyShi","id":2704774,"avatar_url":"https://avatars.githubusercontent.com/u/2704774?v=3","gravatar_id":"","url":"https://api.github.com/users/StonyShi","html_url":"https://github.com/StonyShi","followers_url":"https://api.github.com/users/StonyShi/followers","following_url":"https://api.github.com/users/StonyShi/following{/other_user}","gists_url":"https://api.github.com/users/StonyShi/gists{/gist_id}","starred_url":"https://api.github.com/users/StonyShi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StonyShi/subscriptions","organizations_url":"https://api.github.com/users/StonyShi/orgs","repos_url":"https://api.github.com/users/StonyShi/repos","events_url":"https://api.github.com/users/StonyShi/events{/privacy}","received_events_url":"https://api.github.com/users/StonyShi/received_events","type":"User","site_admin":false},"created_at":"2016-04-15T06:07:38Z","updated_at":"2016-04-15T06:07:38Z","body":"public class WebContextListener implements ApplicationListener {\r\n    private static final Logger logger = LoggerFactory.getLogger(WebContextListener.class);\r\n\r\n    @Override\r\n    public void onApplicationEvent(ApplicationEvent applicationEvent) {\r\n        if (applicationEvent instanceof ContextStartedEvent){\r\n            logger.debug(\"It was Started.\");\r\n        }\r\n\r\n        if (applicationEvent instanceof ContextClosedEvent){\r\n            ContextClosedEvent event = (ContextClosedEvent) applicationEvent;\r\n            if(event.getApplicationContext().getParent()==null){\r\n                logger.debug(\"App context was Closed.\");\r\n                synchronized (Main.class) {\r\n                    try {\r\n                        Main.class.notifyAll();\r\n                    } catch (Throwable e) {}\r\n                }\r\n                Runtime.getRuntime().exit(0);\r\n            }else{\r\n                logger.debug(\"Web context was Closed.\");\r\n            }\r\n            event = null;\r\n        }\r\n    }\r\n}"}}