httpclient建立连接后主动close释放资源,避免thread pool is full

最近遇到线上机器的日志报错: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()

可关闭此输入流并释放与该流关联的所有系统资源
在这里插入图片描述

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值