如何停止由 org.asynchttpclient 创建的线程以防止内存泄漏?

How to stop threads created by org.asynchttpclient to prevent memory leak?

我正在使用 org.asynchttpclient 到 post 异步请求。

关闭 tomcat 时,我收到以下日志:

SEVERE: The web application [/test] appears to have started a thread named [pool-1-thread-1] but has failed to stop it. This is very likely to create a memory leak.
Jul 04, 2017 10:53:00 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

SEVERE: The web application [/test] appears to have started a thread named [AsyncHttpClient-2-1] but has failed to stop it. This is very likely to create a memory leak.
Jul 04, 2017 10:53:00 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

SEVERE: The web application [/test] appears to have started a thread named [AsyncHttpClient-2-2] but has failed to stop it. This is very likely to create a memory leak.
Jul 04, 2017 10:53:00 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks

SEVERE: The web application [/test] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@71513074]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@4aecc2e8]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

如何关闭这些线程以防止内存泄漏。

这更像是一个警告,most 次后可以忽略。当重新加载或关闭上下文时,您将看到此错误。如果您要关闭服务器,那么 JVM 也将关闭并且 os 将清理所有内存。
如果您想尝试在实现 ClosableAsyncHttpClient 上调用 close,它可能会阻止此问题。您可能必须在那里等待,让它完全关闭ose 连接工厂。您可以查看 tomcat 生命周期以添加关闭处理程序来处理 closing 客户端。