【问题标题】:How to resolve tomcat memory leak warning - The web application have started a thread but has failed to stop it如何解决 tomcat 内存泄漏警告 - Web 应用程序已启动线程但未能停止它
【发布时间】:2017-12-07 22:44:30
【问题描述】:

我正在使用 com.ning.async-http-client(1.9.40) 库来发布异步请求。在关闭 tomcat 时,我在 catalina.out 日志中收到以下消息:-

SEVERE: The web application [/xyz] appears to have started a thread named [Hashed wheel timer #1] but has failed to stop it. This is very likely to create a memory leak.
Jul 03, 2017 1:27:15 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [/xyz] appears to have started a thread named [New I/O worker #1] but has failed to stop it. This is very likely to create a memory leak.
Jul 03, 2017 1:27:15 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [/xyz] appears to have started a thread named [New I/O worker #2] but has failed to stop it. This is very likely to create a memory leak.
Jul 03, 2017 1:27:15 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [/xyz] appears to have started a thread named [New I/O boss #3] but has failed to stop it. This is very likely to create a memory leak.
Jul 03, 2017 1:27:15 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [/xyz] appears to have started a thread named [Hashed wheel timer #2] but has failed to stop it. This is very likely to create a memory leak.**

这些线程的状态是:

"New I/O boss #3" prio=10 tid=0x00007ff3a00f9000 nid=0x17a9 runnable [0x00007ff3878f7000]
"New I/O worker #2" daemon prio=10 tid=0x00007ff3a00aa800 nid=0x17a8 runnable [0x00007ff3879f8000]
"New I/O worker #1" daemon prio=10 tid=0x00007ff3a00b8800 nid=0x17a7 runnable [0x00007ff387af9000]
"Hashed wheel timer #2" prio=10 tid=0x00007ff3a020e800 nid=0x17aa waiting on condition [0x00007ff3875f0000]
"Hashed wheel timer #1" prio=10 tid=0x00007ff3a0083000 nid=0x17a6 sleeping[0x00007ff387bfa000]

请提出一种方法来阻止应用程序中的这些线程。

【问题讨论】:

    标签: java tomcat memory-leaks asynchttpclient


    【解决方案1】:

    AsyncHttpClient 实现了Closeable。当您的应用程序关闭时,调用close() 就足够了。

    这将清理AsyncHttpClient使用的资源。

    为了说明:

    public static void main(String[] args) throws Exception {
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        Future<Response> f = asyncHttpClient.prepareGet("http://www.google.com/").execute();
        Response r = f.get();
    
        asyncHttpClient.close(); // when this is commented out, the application won't exit, as the non daemon threads prevent it.
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-27
      • 2011-05-18
      • 2017-12-26
      • 2016-05-22
      • 1970-01-01
      • 2011-08-19
      • 2012-05-05
      • 1970-01-01
      • 2018-02-09
      相关资源
      最近更新 更多