2

I work in a project that uses Spring Boot as framework and that make SOAP call through WebServiceTemplate on HTTP 1.1 protocol. I've implemented an HTTPClient like this:

@Bean
public PoolingHttpClientConnectionManager poolingConnManager() {
    
    PoolingHttpClientConnectionManager ret = new PoolingHttpClientConnectionManager();
    ret.setDefaultMaxPerRoute(5);
    ret.setMaxTotal(10);
    
    return ret;
}

@Bean
public CloseableHttpClient httpClient(PoolingHttpClientConnectionManager poolingConnManager) {
    
    CloseableHttpClient ret = HttpClients.custom()
            .addInterceptorFirst(this.requestHeaderInterceptor)
            .addInterceptorLast(this.requestInterceptor)
            .addInterceptorLast(this.responseInterceptor)
            .setConnectionManager(poolingConnManager)
            .setConnectionTimeToLive(60000L, TimeUnit.MILLISECONDS)
            .build();
    
    return ret;
}

We Know that multiple HTTP request/response can pass in a single TCP connection until server or client close this TCP connection. In fact, when I've checked open connections via CLI or with WireShark I've seen that only one connection per domain can be opened until the server close this connection and so a brand new connection is open. So my questions are:

  1. Is really possible (especially client side) to open a connections pool or re-use closed connections? If yes, what is the problem in the snippet above? And how can I see a pool of connections in action?

  2. If not, what is the purpose of the PoolingHttpClientConnectionManager's API ? And what about the famous connections pool in DB connection?

Jissay
  • 550
  • 9
  • 28
Kagliostro
  • 21
  • 3
  • [This answer](https://stackoverflow.com/a/50901789/2834978) has some info on how the http client pool works, hope it helps. – LMC Apr 29 '21 at 21:39

0 Answers0