SimpleHttpConnectionManager being used incorrectly

2019-02-21 17:56发布

SimpleHttpConnectionManager being used incorrectly. Be sure that HttpMethod.releaseConnection() is always called and that only one thread and/or method is using this connection manager at a time.

Does Anyone know why this error shows up and is causes the files I want to download or to fail and retry or to download uncompleted

Thank you !

2条回答
来,给爷笑一个
2楼-- · 2019-02-21 18:54

Make sure that you don't use SimpleHttpConnectionManager to create and use connections from multiple threads. The simple connection manager is not designed for it - it returns always the same connection, and this is not thread safe.

In a multi-threaded environment, use a different manager that uses a pool of connections. See MultiThreadedHttpConnectionManager.

查看更多
我只想做你的唯一
3楼-- · 2019-02-21 19:02

Prefer to take no credit for this, but as per Eyal Schneider's answer, find more info on using MultiThreadedHttpConnectionManager in Vincent de Villers excellent blog.

Code snippet copied in case the link ever disappears:

HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
GetMethod httpget = new GetMethod("http://www.myhost.com/");
try {
    httpclient.executeMethod(httpget);
    Reader reader = new InputStreamReader(
        httpget.getResponseBodyAsStream(), httpget.getResponseCharSet());
    // consume the response entity
} finally {
    httpget.releaseConnection();
}
查看更多
登录 后发表回答