Tomcat 关闭的时候出现 JDBC 驱动的警告

2017-05-17 22:29:24 +08:00
 h2so4
The web application [ROOT] 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.

应用程序跑的没问题,但是强制解除注册了?用的 mybatis,是要我手动解除么?

2511 次点击
所在节点    问与答
6 条回复
ixiaohei
2017-05-17 23:59:48 +08:00
这个是 tomcat 关闭时候检查内存泄漏的提示,不用管就行了
h2so4
2017-05-18 00:19:11 +08:00
@ixiaohei 他上面显示的是警告选项,和我的 webapp 代码无关的?
Jerry09
2017-05-18 00:30:22 +08:00
你推出之后看进程管理里面有没有 Java 内存泄漏了应该是
honeycomb
2017-05-18 01:17:15 +08:00
有些很旧的 JDBC 驱动会有关不掉的问题
tianshuang
2017-05-18 09:20:14 +08:00
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;


public class AppServletContextListener implements ServletContextListener {

private static final Logger logger = LogManager.getLogger();

@Override
public void contextInitialized(ServletContextEvent sce) {

}

@Override
public void contextDestroyed(ServletContextEvent sce) {

// This manually deregisters JDBC driver, which prevents Tomcat from complaining about memory leaks to this class
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
try {
DriverManager.deregisterDriver(driver);
logger.log(Level.INFO, String.format("deregistering jdbc driver: %s", driver));
} catch (SQLException e) {
logger.log(Level.ERROR, String.format("Error deregistering driver %s", driver), e);
}
}

}
}
h2so4
2017-05-18 11:17:48 +08:00
@honeycomb 5.1.6 版本不低吧

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/362074

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX