网页java老是卡死_HttpClient总是无限卡死,紧急

我们网站大部分功能是通过HttpClient获取其他接口提供的内容,但每隔一两天就会出现访问卡死,设置了超时时间,也无限卡死,经断点查看,是卡在closeableHttp.execute(request);开始执行这行代码后就卡死了,不报错,也不执行结束。

以下是完整代码,已查阅过相关doc,实在解决不了了,大家帮忙看下是哪里写的不对?非常感谢

public String getContent(String url, int timeOut) {

HttpClientBuilder httpBuilder = HttpClientBuilder.create();

if (timeOut > 0) {

RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(timeOut).setConnectTimeout(timeOut).setSocketTimeout(timeOut).build();

httpBuilder.setDefaultRequestConfig(requestConfig);

}

CloseableHttpClient closeableHttp = httpBuilder.build();

HttpGet request = new HttpGet(url);

CloseableHttpResponse response = null;

try {

response = closeableHttp.execute(request);

HttpEntity entity = response.getEntity();

return entity == null ? null : EntityUtils.toString(entity, CharacterSet.UTF8);

} catch (Exception e) {

e.printStackTrace();

return null;

} finally {

try {

if (request != null) {

request.abort();

}

if (response != null) {

response.close();

}

closeableHttp.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值