Juan Martin Desimoni
Juan Martin Desimoni

Reputation: 186

org.apache.commons.httpclient.HttpClient multithreading calls crash

Hi all I use apache's httpclient to make restcalls, everything is working fine, When multiple thread are using this method my app crashes. What is the implementation for this class that is MultithreadSafe.

Here is my code.

        httpClient = new HttpClient();

        HttpMethod method = null;
        method = new GetMethod();

           ... method creation...

        httpClient.executeMethod(method);
        method.releaseConnection();

Thanks in advance. Juan

Upvotes: 0

Views: 181

Answers (1)

Brian Agnew
Brian Agnew

Reputation: 272307

Have you looked at the HttpClient threading documentation ?

To get started one must create an instance of the MultiThreadedHttpConnectionManager and give it to an HttpClient. This looks something like:

      MultiThreadedHttpConnectionManager connectionManager = 
          new MultiThreadedHttpConnectionManager();
      HttpClient client = new HttpClient(connectionManager);

The issue you're having is quite common when using HttpClient out-of-the -box

Upvotes: 1

Related Questions