With HttpClient 3.x there was a static MultiThreadedHttpConnectionManager.shutdownAll() which we invoked from a ServletContextListener#contextDestroyed() to clean up all potentially hanging threads (prevent classloader leaks).

With HttpClient 4.x this is gone but there's PoolingClientConnectionManager. However, it's got no static methods to shutdown connections.

How to go about this?

有帮助吗?

解决方案

Inclusion of this method in HC 3.1 was a mistake. Generally I can see no reason for having more than pool of connections per distinct HTTP service. It should not be that difficult to keep track of one or two connection managers and shut them down when necessary. Having said that, if for whatever reason you really need to shut down all active connection managers indiscriminately you can use the same technique as used by HC as of version 4.3-beta2 when running inside a OSGi container: basically keeping track of HttpClient instances created by a custom HttpClientBuilder and shutting them down when the container is shut down or the bundle is reloaded

https://svn.apache.org/repos/asf/httpcomponents/httpclient/tags/4.3-beta2/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiHttpClientBuilder.java

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top