title: Using Apach HttpClient v4.5, How can I reuse a keep-alive connection to trigger many HTTP request?
body: <p>when handling a request, my backend will trigger many HTTP request using Apach HttpClient to a host.</p>
  <p>I find now every time it trigger a HTTP reqeust,a new <code>HttpClient</code> (<code>DefaultHttpClient</code>, which is deprecated) will be created and used.</p>
  <p>Altought these requests are HTTP requests, but their target host are the same, the only different thing is their POST body.</p>
  <p><strong>Q1. So, can I reuse a keep-alive connection (which should be a keep-alive TCP connection if there is) to trigger these request to reduce cost time on client.execute?</strong></p>
  <p>What I have tried:</p>
  <p>I think everytime a new DefaultHttpClient instance obviously cannot hold a keep-alive connection, so I register a HttpClient spring Bean and resue it.</p>
  <p>and when creating the HttpClient Bean:</p>
  <pre class="lang-java prettyprint-override"><code>        return HttpClientBuilder.create()
                  .setConnectionManager(new PoolingHttpClientConnectionManager(3000, TimeUnit.MICROSECONDS))
  </code></pre>
  <p>set a <code>PoolingHttpClientConnectionManager</code> for it.</p>
  <p>However, The final result shows that the time spent on httpClient.execute increases instead.</p>
  <p><strong>Q2. the <code>PoolingHttpClientConnectionManager</code>, is its target to make a HttpClient able to be reused to open many connection and doesn't it match my goal (there should be only one connection and many POST requests are made concurrently based on this connection)?</strong></p>
  <p>Thanks a lot.</p>