Tomcat Guice/JDBC Memory Leak

后端 未结 9 2023
长发绾君心
长发绾君心 2020-11-27 12:14

I\'m experiencing a memory leak due to orphaned threads in Tomcat. Particularly, it seems that Guice and the JDBC driver are not closing threads.

Aug 8, 2012         


        
9条回答
  •  感情败类
    2020-11-27 12:43

    I just dealt with this problem myself. Contrary to some other answers, I do not recommend issuing the t.stop() command. This method has been deprecated, and for good reason. Reference Oracle's reasons for doing this.

    However there is a solution for removing this error without needing to resort to t.stop()...

    You can use most of the code @Oso provided, just replace the following section

    Set threadSet = Thread.getAllStackTraces().keySet();
    Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);
    for(Thread t:threadArray) {
        if(t.getName().contains("Abandoned connection cleanup thread")) {
            synchronized(t) {
                t.stop(); //don't complain, it works
            }
        }
    }
    

    Replace it using the following method provided by the MySQL driver:

    try {
        AbandonedConnectionCleanupThread.shutdown();
    } catch (InterruptedException e) {
        logger.warn("SEVERE problem cleaning up: " + e.getMessage());
        e.printStackTrace();
    }
    

    This should properly shutdown the thread, and the error should go away.

提交回复
热议问题