Search code examples
springconnection-poolingresttemplate

Springs RestTemplate default connection pool


Just wondering if RestTemplate out of the box uses connection pooling or does it simply establish a new connection each time ?


Solution

  • 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