Prabhjot Prabhjot - 25 days ago 8x
Java Question

HttpClient executeMethod throws Connection reset

I have a java program which creates multiple threads where each thread makes POST request. It works fine most of the time but under heavy load it throws Connection reset exception. For example, when I made 40 simultaneous requests, couple of time I got Connection reset exception.

Caught: Connection reset Connection reset
at org.apache.commons.httpclient.HttpParser.readRawLine(
at org.apache.commons.httpclient.HttpParser.readLine(
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMetho
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodB
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.j
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Htt
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMe
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav

In my Java code, I am creating an instance of HttpClient

HttpClient client = new HttpClient();

The problem does not happen when I make one request wait for it to finish and then make another request. However, the moment I turn the program into multi-threading I get this issue.

Could anyone please point out how could I prevent this exception and then retry again. From google, I found out the answer may be along the lines of using


I am trying to use this in the mean time but any other suggestions are welcome.


I recommend either using a MultiThreadedHttpConnectionManager if you're using HttpClient 3 or PoolingHttpClientConnectionManager if you're using HttpClient 4.

I'm fairly confident that the default connection manager for both HttpClient 3 and HttpClient 4 are expecting only single thread access.