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