简体   繁体   中英

How to resolve tomcat memory leak warning - The web application have started a thread but has failed to stop it

I am using com.ning.async-http-client(1.9.40) library to post asynchronous request. While shutting down tomcat, I am getting below messages in catalina.out log :-

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

The state of these threads are:

"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]

Please suggest a way to stop these threads from application.

The AsyncHttpClient implements Closeable . It suffices to call close() on it when your application shuts down.

This will clean up the resources used by AsyncHttpClient .

To illustrate :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM