dcohra
Last Updated: April 26, 2016
·
13.31K
· zohebsait
1ffc0aa64a40846eb10f2e11a7239b08

Connection Pooling with Spring RestTemplate

If you are using Spring MVC's RestTemplate to make REST calls, it is important to realize that it doesn't use HTTP connection pooling of any kind, and will establish and close a connection every time you make a REST call.

If you want to use connection pooling, you would need to provide another implementation of ClientHttpRequestFactory. A good option is to use the org.springframework.http.client.HttpComponentsClientHttpRequestFactory() which is provided with Spring.

new org.springframework.web.client.RestTemplate(new HttpComponentsClientHttpRequestFactory())

Of course, if you look up the documentation for HttpComponentsClientHttpRequestFactory, you can configure a lot of the connection pooling parameters.

3 Responses
Add your response

17788
None

Thank you very much for the info, great help.

over 1 year ago ·
21197
None

What is the performance increase by using connection pool? When does it make sense to use it?

Thanks

over 1 year ago ·
22841
Identicon

Thanks for this tip, just what I was looking for. Sadly this doesn't seem to be part of the official documentation.

over 1 year ago ·