Search code examples
javaspringconnection-poolingapache-httpclient-4.xresttemplate

PoolingHttpClientConnectionManager for a single host/route


So I have a spring application and I use PoolingHttpClientConnectionManager to creation a connection pool for all http requests that go out of this application. I only have one host to call which means there is only one route.

 @Bean
      public PoolingHttpClientConnectionManager getPHCM() {
        PoolingHttpClientConnectionManager phcm = new PoolingHttpClientConnectionManager();
        phcm.setMaxTotal(50);
        phcm.setDefaultMaxPerRoute(50);
        return phcm;
      }

I am wondering if this configuration will create and reserve all 50 connections for one single route that I have ? I find setting MaxPerRoute value redundant but not sure if that is also what I need for my case.


Solution

  • I am wondering if this configuration will create and reserve all 50 connections

    No, it will not. HttpClient will keep persistent connection alive as long as there is room in the connection pool but it will not proactively create connections.