Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleHttpConnectionManager being used incorrectly

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 !

like image 578
MArio Avatar asked Jun 21 '10 21:06

MArio


2 Answers

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.

like image 56
Eyal Schneider Avatar answered Nov 01 '22 11:11

Eyal Schneider


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();
}
like image 10
wmorrison365 Avatar answered Nov 01 '22 10:11

wmorrison365