Tomcat Guice/JDBC 内存泄漏 [英] Tomcat Guice/JDBC Memory Leak

查看:21
本文介绍了Tomcat Guice/JDBC 内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 Tomcat 中的孤立线程,我遇到了内存泄漏.特别是,Guice 和 JDBC 驱动程序似乎没有关闭线程.

2012 年 8 月 8 日下午 4:09:19 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads严重:Web 应用程序似乎启动了一个名为 [com.google.inject.internal.util.$Finalizer] 的线程,但未能阻止它.这很可能造成内存泄漏.2012 年 8 月 8 日下午 4:09:19 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads严重:Web 应用程序似乎启动了一个名为 [Abandoned connection cleanup thread] 的线程,但未能将其停止.这很可能造成内存泄漏.

我知道这类似于其他问题(例如这个),但就我而言,别担心"的答案是不够的,因为它给我带来了问题.我有定期更新这个应用程序的 CI 服务器,在 6-10 次重新加载后,CI 服务器会因为 Tomcat 内存不足而挂起.

我需要能够清除这些孤立线程,以便更可靠地运行我的 CI 服务器.任何帮助将不胜感激!

解决方案

我刚刚自己处理了这个问题.与其他一些答案相反,我不建议发出 t.stop() 命令.此方法已被弃用,这是有充分理由的.参考 Oracle 这样做的原因.>

然而,有一种解决方案可以消除此错误,而无需求助于 t.stop()...

你可以使用@Oso提供的大部分代码,只需替换以下部分

设置<线程>threadSet = Thread.getAllStackTraces().keySet();线程[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);for(线程t:threadArray){if(t.getName().contains("废弃的连接清理线程")) {同步(t){停止();//不要抱怨,它有效}}}

使用MySQL驱动提供的以下方法替换:

尝试{AbandonedConnectionCleanupThread.shutdown();} catch (InterruptedException e) {logger.warn("清理严重问题:" + e.getMessage());e.printStackTrace();}

这应该会正确关闭线程,错误应该会消失.

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 4:09:19 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [com.google.inject.internal.util.$Finalizer] but has failed to stop it. This is very likely to create a memory leak.
Aug 8, 2012 4:09:19 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A 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.

I know this is similar to other questions (such as this one), but in my case, the answer of "don't worry about it" won't be sufficient, as it is causing problems for me. I have CI server which regularly updates this application, and after 6-10 reloads, the CI server will hang because Tomcat is out of memory.

I need to be able to clear up these orphaned threads so I can run my CI server more reliably. Any help would be appreciated!

解决方案

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<Thread> 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.

这篇关于Tomcat Guice/JDBC 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆