SimpleHttpConnectionManager is misused

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

Does anyone know why this error appears and causes the files I want to download, or crash and try again or download incomplete

Thanks!

+7
java apache-commons
source share
3 answers

Make sure you are not using the SimpleHttpConnectionManager to create and use connections from multiple threads. A simple connection manager is not designed for it - it always returns the same connection, and it is not thread safe.

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

+11
source

I prefer not to take any account for this, but as the answer from Eyal Schneider, find more information on using the MultiThreadedHttpConnectionManager on the excellent Vincent de Villers blog .

The code fragment is 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(); } 
+3
source

Does anyone know why this error appears, and is it causing the files I want to download, or crash, try again, or download incomplete ones?

Most likely, the error is in the application that is trying to download. But without any other context (for example, source code, stack traces), we would have left guesses as the only "tool" to figure out what the real mistake is.

0
source

All Articles