Springs RestTemplate默认连接池 [英] Springs RestTemplate default connection pool
问题描述
只是想知道RestTemplate是否开箱即用使用连接池,还是只是每次都建立一个新的连接?
Just wondering if RestTemplate out of the box uses connection pooling or does it simply establish a new connection each time ?
推荐答案
我相信RestTemplate
不会使用连接池发送请求,它会使用SimpleClientHttpRequestFactory
来包装标准JDK
的
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.
实际上,您可以将RestTemplate
配置为使用池化的实现,例如HttpComponentsClientHttpRequestFactory
,但是最有可能的是,您可能还需要配置一些设置以防止请求超时.
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.
我在疑难解答中写了关于此问题的博客. Spring的RestTemplate请求超时
这篇关于Springs RestTemplate默认连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!