提问者:小点点

关闭CloseableHttpClient时,我是否还必须关闭PoolingHttpClientConnectionManager?


PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
connManager.setMaxTotal(120);
connManager.setDefaultMaxPerRoute(20);
   
CloseableHttpClient httpClient = HttpClientBuilder.create()
    .setConnectionManager(connManager)
    .build();

关闭httpClient就足够了吗?还是我还必须显式关闭连接管理器?

httpClient.close(); // Is this enough?

共1个答案

匿名用户

同时找到了答案。AbstractHttpClient似乎关闭了连接管理器。所以我认为关闭httpclient应该没问题。

请参阅org. apache.http.implp.client.AbstractHttpClient

@Override
public void close() {
    getConnectionManager().shutdown();
}