Invalid use of SingleClientConnManager: connection still allocated解决方案

来源:互联网 发布:网络灰色项目一天一万 编辑:程序博客网 时间:2024/05/17 22:01

在做项目的时候,看到后台打印的这样的错误

09-25 15:02:14.741: W/SingleClientConnManager(16430): Invalid use of SingleClientConnManager: connection still allocated.
09-25 15:02:14.741: W/SingleClientConnManager(16430): Make sure to release the connection before allocating another one.

 此问题出现原因是使用同一个httpclient当 前一个post|get请求尚未结束,另条线程又再次使用该httpclient请求数据,则前一个会报出如上错误

 出现原因

 1: 每次重新New一个新的httpclien,进行请求

 2:post/get没有关闭,没有写post.abort()或者 EntityUtils.consume(entity);

 3:涉及到多线程调用同一个httpclient

    解决方案考虑加同步块

       synchronized(httpclient){
                response=httpclient.execute(get);
                entity=response.getEntity();
               EntityUtils.consume(entity);
      }

    EntityUtils.toString(entity)

其实这个问题可以直接用httpclient的多线程解决,没必要这么麻烦

二:非法uri问题

      一些asp网站中,常常出现url例如www.baidu.com?q=%34ut%3333  这个url不是合法的uri却是合法的url。

     而httpclient4.1中无论httpget、httppost都是用uri而非url,曾尝试反编译,改源代码,一看工作量实在太大,只好放弃,此问题小弟没有其他方法,只好拿起httpclient3.1

     真不知道httpclient4基于uri是什么原因......还望高手教教俺

0 0
原创粉丝点击