关于tomcat在关闭时的memory leak日志信息的解释

来源:互联网 发布:淘宝c店开店流程 编辑:程序博客网 时间:2024/06/09 22:45

关于tomcat在关闭时的memory leak日志信息的解释:


现象:在shutdowntomcat的时候出现一些如下异常:

May 16, 2017 10:28:50 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc

SEVERE: The web application [] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

May 16, 2017 10:28:50 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc

SEVERE: The web application [] 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.

May 16, 2017 10:28:50 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

SEVERE: The web application [] appears to have started a thread named [FileWatchdog] but has failed to stop it. This is very likely to create a memory leak.

May 16, 2017 10:28:50 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

SEVERE: The web application [] appears to have started a thread named [New I/O server boss #1 ([id: 0x445212ca, /0.0.0.0:20881])] but has failed to stop it. This is very likely to create a memory leak.

May 16, 2017 10:28:50 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

SEVERE: The web application [] appears to have started a thread named [dubbo-remoting-server-heartbeat-thread-1] but has failed to stop it. This is very likely to create a memory leak


在查询tomcat的官方解释中有个链接https://wiki.apache.org/tomcat/MemoryLeakProtection详细的阐述了tomcat自6.0.25版本后的内存泄漏检测和修复保护机制。


在关于JDBC driver部分是这样解释的:

If a webapp contains a JDBC driver (e.g. in WEB-INF/lib), the driver will be registered with theDriverManager when it is first used. When the application is stopped, the driver should be deregistered withDriverManager to avoid a classloader leak. Since applications usually forget this, tomcat helps by deregistering the driver.


大体意思:如果应用包含了JDBC驱动包在WEB-INF/lib下(也就是使用到了数据库驱动),当驱动第一次被使用到时就会被驱动管理器注册。当应用在停止时,为避免类加载泄漏,此时驱动应该被驱动管理注销掉。但是自从应用经常忘记做这个事情,tomcat就帮助强制注销此驱动,也就有了日志的出现—The web application [] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.


此时知道大概原因,就去DruidDriver里面看看有没有做DriverManager.deRegisterDriver(driver)方法了,在经过查看DruidDriver类只发现了DriverManager.registerDriver(driver);

而没有调用过DriverManager.deRegisterDriver(driver);

由此可以看出问题的原因了。经过查看com.mysql.jdbc.Driver,也是没有注销的方法。



解决方法:

1.写个子类继承Driver然后实现DriverManager.deRegisterDriver(driver)方法。

2.在tomcat中配置不打印这些异常。

3.也可以不管这个异常

阅读全文
0 0