tomcat 6.0.44 “has failed to stop it. This is very likely to create a memory leak” 问题调查

1. 问题起因

我们项目中缓存模块某个实现采用了ehcache(2.4.3),当项目部署到tomcat中后,对tomcat做停止服务操作,发现tomcat不能正常停止,报错 appears to have started a thread named [xxx] but has failed to stop it. This is very likely to create a memory leak.java进程不能正常结束,需要手动kill进程。

信息: Stopping service Catalina
2015-9-26 11:40:17 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/hd] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2015-9-26 11:40:17 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/hd] appears to have started a thread named [pool-2-thread-1] but has failed to stop it. This is very likely to create a memory leak.
2015-9-26 11:40:17 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/hd] appears to have started a thread named [[email protected]] but has failed to stop it. This is very likely to create a memory leak.
2015-9-26 11:40:17 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/hd] appears to have started a thread named [org.hibernate.cache.spi.UpdateTimestampsCache.data] but has failed to stop it. This is very likely to create a memory leak.
2015-9-26 11:40:17 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/hd] appears to have started a thread named [org.hibernate.cache.internal.StandardQueryCache.data] but has failed to stop it. This is very likely to create a memory leak.
2015-9-26 11:40:17 org.apache.coyote.http11.Http11Protocol destroy
信息: Stopping Coyote HTTP/1.1 on http-8080

2. ehcache 线程不会自动停止问题

分析后,发现是ehcache的三个线程不能自动停止(或者说ehcache未在应用停止/jvm停止的时候将其结束)。

经分析后发现可以在web应用中加listener,在应用destory的时候触发ehcache的释放资源与线程的调用。

3. 一定要加listener吗?

分析ehcache代码后发现,使用系统参数-Dnet.sf.ehcache.enableShutdownHook=true能启用ehcache的jvm shutdown hook。

net.sf.ehcache.CacheManager

/**
     * Some caches might be persistent, so we want to add a shutdown hook if that is the
     * case, so that the data and index can be written to disk.
     */
    private void addShutdownHookIfRequired() {

        String shutdownHookProperty = System.getProperty(ENABLE_SHUTDOWN_HOOK_PROPERTY);
        boolean enabled = PropertyUtil.parseBoolean(shutdownHookProperty);
        if (!enabled) {
            return;
        } else {
            LOG.info("The CacheManager shutdown hook is enabled because {} is set to true.", ENABLE_SHUTDOWN_HOOK_PROPERTY);

            Thread localShutdownHook = new Thread() {
                @Override
                public void run() {
                    synchronized (this) {
                        if (status.equals(Status.STATUS_ALIVE)) {
                            // clear shutdown hook reference to prevent
                            // removeShutdownHook to remove it during shutdown
                            shutdownHook = null;
                            LOG.info("VM shutting down with the CacheManager still active. Calling shutdown.");
                            shutdown();
                        }
                    }
                }
            };

            Runtime.getRuntime().addShutdownHook(localShutdownHook);
            shutdownHook = localShutdownHook;
        }
    }

jvm shutdown hook注意点:

tomcat自带的shutdown.sh/bat不能给java进程发送退出信号,jvm shutdown hook不能被触发。

需要使用kill $pid,jvm shutdown hook 才能被触发

4. 之前的项目用了hibernate3,二级缓存依赖ehcache,为什么没有这个问题

难道是在什么地方加了destory?

准备demo,验证,存在一样的问题。只是由于hibernate3(3.2.5ga)依赖较低版本的ehcache(1.2.3),所以没有被停掉的线程是hibernate和其他一些部件的。

日志如下:

2015-9-26 10:53:15 org.apache.catalina.core.StandardService stop
信息: Stopping service Catalina
2015-9-26 10:53:15 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/hd] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2015-9-26 10:53:15 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/hd] appears to have started a thread named [Store org.hibernate.cache.UpdateTimestampsCache Spool Thread] but has failed to stop it. This is very likely to create a memory leak.
2015-9-26 10:53:15 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/hd] appears to have started a thread named [Store org.hibernate.cache.UpdateTimestampsCache Expiry Thread] but has failed to stop it. This is very likely to create a memory leak.
2015-9-26 10:53:15 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/hd] appears to have started a thread named [Store org.hibernate.cache.StandardQueryCache Spool Thread] but has failed to stop it. This is very likely to create a memory leak.
2015-9-26 10:53:15 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/hd] appears to have started a thread named [Store org.hibernate.cache.StandardQueryCache Expiry Thread] but has failed to stop it. This is very likely to create a memory leak.
2015-9-26 10:53:15 org.apache.coyote.http11.Http11Protocol destroy
信息: Stopping Coyote HTTP/1.1 on http-8080
2015-9-26 10:53:15 org.apache.catalina.loader.WebappClassLoader loadClass

那以前的项目都上线了,为什么没这个问题?

难道是tomcat版本?将tomcat版本从6.0.44切换到6.0.37,发现问题不再能复现了。也就是说6.0.37的tomcat并没有在shutdown的时候做这样的检查。

时间: 2025-01-20 04:16:15

tomcat 6.0.44 “has failed to stop it. This is very likely to create a memory leak” 问题调查的相关文章

警告: The web application [ROOT] appears to have started a thread named [Thread-48] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:

1. 问题描述 tomcat跑web项目(其中依赖java项目) 出现大量上述警告 项目起不来 关键字 memory leak 内存泄漏 2. 解决方案 难道是程序写的有问题? 最终 将tomcat VM参数中 内存调大 解决了 -Xms512m -Xmx512m -Xmn300m -Xss2048k -XX:PermSize=512m -XX:MaxPermSize=512m 需要根据机器的配置做相应调整

大神的---解决tomcat内存溢出问题----tomcat报错:This is very likely to create a memory leak问题解决

tomcat memory leak解决方案 这种问题在开发中经常会碰到的,看看前辈的总结经验 Tomcat内存溢出的原因  在生产环境中tomcat内存设置不好很容易出现内存溢出.造成内存溢出是不一样的,当然处理方式也不一样. 这里根据平时遇到的情况和相关资料进行一个总结.常见的一般会有下面三种情况:  1.OutOfMemoryError: Java heap space  2.OutOfMemoryError: PermGen space  3.OutOfMemoryError: unab

tomcat报错:This is very likely to create a memory leak问题解决

tomcat memory leak解决方案 这种问题在开发中经常会碰到的,看看前辈的总结经验 Tomcat内存溢出的原因  在生产环境中tomcat内存设置不好很容易出现内存溢出.造成内存溢出是不一样的,当然处理方式也不一样.  这里根据平时遇到的情况和相关资料进行一个总结.常见的一般会有下面三种情况:  1.OutOfMemoryError: Java heap space  2.OutOfMemoryError: PermGen space  3.OutOfMemoryError: una

Server Apache Tomcat v7.0 at localhost failed to start.

自己在学习servlet中,突然启动不了Tomcat7服务器,提示出现如下错误: 百度之后,没有找到解决办法,偶然发现是我的Web-content下--WEB-INF下--web.xml的配置文件内 <servlet> <servlet-name>lifeServlet</servlet-name> <servlet-class>cn.ac.azure.LifeServlet</servlet-class> </servlet> &l

Tomcat运行一段时间后,自动停止关闭,To prevent a memory leak,Druid 数据库连接自动关闭, the JDBC Driver has been forcibly unregistered.

1. Tomcat 错误日志 tail -100f tomcat9/logs/catalina.out 21-Sep-2017 23:05:39.301 INFO [Thread-5] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8809"]21-Sep-2017 23:05:39.352 INFO [Thread-5] org.apache.catalina.core.Stand

解决:The web application [] registered the JDBC driver [] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

问题描述 在将Spring Boot程序打包生成的war包部署到Tomcat后,启动Tomcat时总是报错,但是直接在IDEA中启动Application或者用"java -jar"方式运行jar包时都能正常运行.报错信息如下: To prevent a memory leak, the JDBC Driver has been forcibly unregistered. (为了防止内存泄漏,已强制注销JDBC驱动程序.) 开发环境 Spring Boot + MySql + Spr

tomcat关闭时Log4j2报错 Log4j Log4j2-TF-4-Scheduled-1 memory leak

出错信息: 23-Sep-2017 17:43:18.964 警告 [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [license] appears to have started a thread named [Log4j2-TF-4-Scheduled-1] but has failed to stop it. This is very li

Android-67-Tomcat启动出错:Server Tomcat v7.0 Server at localhost failed to start.

 错误:Server Tomcat v7.0 Server at localhost failed to start.如图: 唉!!!!图片上传不上去,悲哀啊!!!只能先写着错误提示语吧~~- 解决办法: 1.In Eclipse, Open the"Server" tab. 2.Double click on the "Tomcat6" entry to see the configuration. 3.Then click on the "Open

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/Users/lonecloud/tomcat/apache-tomcat-7.0.70 2/webapps/myproject/WEB-INF/classes/cn/lone

解决这个报错的解决办法: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/Users/lonecloud/tomcat/apache-tomcat-7.0.70 2/webapps/myproject/WEB-INF/classes/cn/lonecloud/dao/Impl/UserDaoImpl.class]; ne