HttpClient:connection still allocated.解决方法

来源:互联网 发布:js onload方法 编辑:程序博客网 时间:2024/05/18 00:11
org.apache.http.client.HttpClient使用中,报了以下的异常:
Invalid use of SingleClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
此问题出现原因是并发调用同一个httpclient去请求数据。在上一个post|get请求尚未结束时,又启新的线程再次使用该httpclient请求数据。
目前我的解决方法是用synchronized关键字同步httpclient请求数据的操作。但这个解决方案不能解决并发使用同一个httpClient请求数据的需求,本人对httpclient不精通,有更好解决方法的大神,请不吝赐教!
0 0