tomcat停止出現內存泄漏

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.

Jun 30, 2018 8:57:08 AM 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.

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

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

Jun 30, 2018 8:57:08 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

SEVERE: 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.

以上是tomcat報出的錯誤信息。




原因分析:通過查詢大量資料,同時結合自己的項目情況,分析得出引起tomcat memory leak 的原因有:

       1、jdbc Driver在tomcat運行時進行註冊,但是當tomcat停止時沒有解除註冊;

       2、使用quartz跑定時任務時,tomcat停了,quartz的線程沒有停掉;

       3、web 容器重啓一個叫Abandoned connection cleanup thread的線程失敗.

解決辦法:

        1、用腳本語言代替quartz的定時任務或將quartz與業務代碼剝離開來;

        2、手動反註冊jdbc驅動,清理Abandoned connection cleanup thread。

import com.mysql.jdbc.AbandonedConnectionCleanupThread;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by yinguo on 2018-06-26.
 */
public class QuartzContextListener implements ServletContextListener {

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        System.out.println("webService stop");
        try {
            while(DriverManager.getDrivers().hasMoreElements()) {
                DriverManager.deregisterDriver(DriverManager.getDrivers().nextElement());
            }
            System.out.println("jdbc Driver close");
            AbandonedConnectionCleanupThread.shutdown();
            System.out.println("clean thread success");
        } catch (SQLException e) {
            e.printStackTrace();
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        System.out.println("webService start");
    }
}

        最後再說一點,解決方案千篇一律,還是要具體問題具體分析!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章