HttpClient总是无限卡死,紧急
时间: 2015-06-24来源:开源中国
前景提要
HDC调试需求开发(15万预算),能者速来!>>>
我们网站大部分功能是通过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(); } } }




科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行