最近遇到线上机器的日志报错:error message:[]Error log: thread pool is full
定位原因是httpclient创建连接后没有及时关闭,为了关闭连接,特意找到了两种关闭连接的方法
方法1:关闭CloseableHttpResponse (推荐)
* Closes this stream and releases any system resources associated
* with it. If the stream is already closed then invoking this
* method has no effect.
close方法解释:关闭此流并释放与其关联的所有系统资源。 如果流已经关闭,则调用此方法无效
public static void release(CloseableHttpResponse httpResponse, CloseableHttpClient httpClient) throws IOException {
// 释放资源
if (httpResponse != null) {
httpResponse.close();
}
if (httpClient != null) {
httpClient.close();
}
}
方法2:不能直接close时,可使用response.getEntity().getContent().close()
可关闭此输入流并释放与该流关联的所有系统资源