根据定义,PoolingHttpClientConnectionManager 可以重用连接。那么,
1)在使用后是否需要显式释放连接?
2)如果连接被释放,管理器将无法重用该连接?
1)在使用后是否需要显式释放连接?
2)如果连接被释放,管理器将无法重用该连接?
executing a method?
CloseableHttpClient closableHttpClient = HttpClients.custom().setConnectionManager(getPoolingHttpClientConnectionManager()).build();
HttpPost post = new HttpPost(resourcePath);
try {
return closableHttpClient.execute(post);
} catch (IOException e) {
//handle exception
}finally {
post.releaseConnection();
}
CloseableHttpResponse
最终会关闭连接。根据您之前的帖子,您可能正在尝试以多线程方式执行池化。请参见Threaded Request Execution example,其他示例在此处找到。还可以在第2.4节中找到更多解释。 - Paul Samsotha