title: HttpClient and RestTemplate - Concurrency exception
body: <p>I'm using the following configuration :</p>
  
  <pre><code>&lt;bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"&gt;
      &lt;!-- &lt;constructor-arg ref="httpClientParams"/&gt; --&gt;
   &lt;/bean&gt;
  
   &lt;bean id="httpClientFactory"
      class="org.springframework.http.client.CommonsClientHttpRequestFactory"&gt;
      &lt;constructor-arg ref="httpClient" /&gt;
  &lt;/bean&gt;
  
   &lt;bean id="restTemplate" name="restTemplate"
      class="org.springframework.web.client.RestTemplate"
      autowire-candidate="true"&gt;
      &lt;constructor-arg ref="httpClientFactory" /&gt;
  </code></pre>
  
  <p>My environment is using multiple threads that tries to invoke restTemplate.</p>
  
  <p>I get the following warning from time to time:</p>
  
  <pre><code> WARN SimpleHttpConnectionManager - 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.
  </code></pre>
  
  <p>followed by the exception:</p>
  
  <pre><code>java.lang.NullPointerException
  at org.apache.commons.httpclient.HttpConnection.isStale(HttpConnection.java:515)
  at org.apache.commons.httpclient.HttpConnection.closeIfStale(HttpConnection.java:431)
  at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
  at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
  at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
  at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
  at org.springframework.http.client.CommonsClientHttpRequest.executeInternal(CommonsClientHttpRequest.java:85)
  at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:46)
  at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:49)
  at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:488)
  at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:452)
  at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:302)
  </code></pre>
  
  <p>Any ideas how to fix my configuration?</p>
  
  <p>P.S I tried the following with no success:</p>
  
  <pre><code>&lt;bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"&gt;
      &lt;constructor-arg ref="httpClientParams" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams"&gt;
      &lt;property name="connectionManagerClass"
          value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager" /&gt;
  &lt;/bean&gt;
  </code></pre>