SSM项目关闭时报错:[Abandoned connection cleanup thread] but has failed to stop it...



SSM整合小项目关闭时tomcat报错
The web application [] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak

原因似乎是数据库的驱动无法释放。
解决方法:

  • 自定义一个监听器,用于终止mysql进程:
public class DriverMangerListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {

    }

    public void contextDestroyed(ServletContextEvent sce) {
        Enumeration<Driver> enumeration = DriverManager.getDrivers();
        while (enumeration.hasMoreElements()) {
            try {
                DriverManager.deregisterDriver(enumeration.nextElement());
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
  • 将该监听器在web.xml中配置:
<listener>
      <listener-class>com.ssm.listener.DriverMangerListener</listener-class>
</listener>
  • pom.xml中删除mysql驱动包依赖,将驱动包放到tomcat安装目录的lib目录下。
  • ok。

参考:https://blog.csdn.net/www646288178/article/details/79391940


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM