Springs RestTemplate default connection pool
I believe RestTemplate
doesn’t use a connection pool to send requests, it uses a SimpleClientHttpRequestFactory
that wraps a standard JDK
’s HttpURLConnection
opening and closing the connection.
Indeed you can configure RestTemplate
to use a pooled implementation such as HttpComponentsClientHttpRequestFactory
but most-likely you might also need to configure some settings to prevent requests from timing out.
I have blogged about this issue at Troubleshooting Spring's RestTemplate Requests Timeout
Yes, Spring RestTemplateBuilder
uses Apache HttpClient for pooling (usage).
RestTemplateBuilder
creates HttpComponentsClientHttpRequestFactory
and uses HttpClientBuilder
.
HttpClientBuilder
, by default, sets pool size per route (host) to 5 and total pool size to 10 (source):
s = System.getProperty("http.maxConnections", "5");
int max = Integer.parseInt(s);
poolingmgr.setDefaultMaxPerRoute(max);
poolingmgr.setMaxTotal(2 * max);
To check connection pool logging set logging level as follows:
org.apache.http.impl.conn.PoolingHttpClientConnectionManager=TRACE