HttpClient4.X Invalid use of SingleClientConnManager: connection still allocated
来源:互联网 发布:javascript 最新版本 编辑:程序博客网 时间:2024/04/30 10:40
HttpClient4.X Invalid use of SingleClientConnManager: connection still allocated问题
项目用到了httpclient4.1开发。在多线程的情况下,异常报
Invalid use of SingleClientConnManager: connection still allocated
从国外的一张帖子看到,httpclient默认使用的是SingleClientConnManager,但在并发环境下最好使用ThreadSafeClientConnManager。代码如下:
HttpClient client = new DefaultHttpClient(new ThreadSafeClientConnManager());
HttpGet httpGet = null;
InputStream in = null;
try {
httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null) {
in = response.getEntity().getContent();
return EntityUtils.toByteArray(responseEntity);
}
} finally {
if (httpGet != null) {
httpGet.abort();
}
IOUtils.closeQuietly(in);
}
return null;
这样就可以避免发生异常,感谢国外的这个帖子
http://old.nabble.com/HttpClient-instance-management-td24185137.html
http超时处理:
使用是apache的HttpClient:
DefaultHttpClient:
请求超时
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000);
读取超时
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 60000);
HttpClient
HttpClient httpClient=new HttpClient();
链接超时
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(60000);
读取超时
httpClient.getHttpConnectionManager().getParams().setSoTimeout(60000)
- HttpClient4.X Invalid use of SingleClientConnManager: connection still allocated问题
- HttpClient4.X Invalid use of SingleClientConnManager: connection still allocated
- Invalid use of SingleClientConnManager: connection still allocated
- Invalid use of SingleClientConnManager: connection still allocated.
- W/SingleClientConnManager(1155):Invalid use of SingleClientConnManager: connection still allocated.
- httpclient4.1.2抓数据Invalid use of SingleClientConnManager: connection still allocated解决方案
- Invalid use of SingleClientConnManager: connection still allocated解决方案
- Invalid use of BasicClientConnManager: connection still allocated.
- Invalid use of BasicClientConnManager: connection still allocated.
- httpclient Invalid use of SingleClientConnManager: connection still alloc
- Invalid use of BasicClientConnManager: connection still allocated解决方案
- Invalid use of SingleClientConnManager: connection still allocatedMake sure to release the connectio
- 调用rest地址时异常:Invalid use of BasicClientConnManager: connection still allocated.
- HttpClient:connection still allocated.解决方法
- connection 'qt_sql_default_connection' is still in use
- some use of connection
- some use of connection
- QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use
- [阿里笔试] 2016阿里校招业务性产品经理(商业领域)笔试题
- 针对TQ部分ARM开发板中QTCPServer不能接受数据的问题
- webdriver报不可见元素异常方法总结
- 网易互娱2017实习生招聘在线笔试第一场-题目3
- 整理的一些常用的Java日期时间上面的操作
- HttpClient4.X Invalid use of SingleClientConnManager: connection still allocated
- retrofit 如何查看日志
- java 小结 (四)
- Invalid use of BasicClientConnManager: connection still allocated.
- Dubbo学习(六):多注册中心
- HttpsURLConnection
- java 实现两个日期之间所有日期的遍历
- java小程序之猜生日
- 关于Java Swing怎么实时刷新JTextArea,以显示刚才加append的内容(线程角度)