使用 Spring Rest 模板时 HttpConnection 的默认保持活动时间
Default keep-alive time for a HttpConnection when using Spring Rest Template
我想知道在通过 Spring rest 模板创建新连接之前,HttpConnection 在不活动时保持活动状态多长时间。我查看了默认的连接超时和读取超时参数,但我相信这些是在连接超时的上下文中使用的,当连接由于某些故障等而未建立时。
我正在寻找的是,如果没有 activity(或)不活动,连接将保持活动状态多长时间,以及如何通过 Spring Rest 模板(或)配置它底层机制。
默认情况下 RestTemplate
使用 SimpleClientHttpRequestFactory
进而打开 Java 的 HttpURLConnection
which by default supports keep-alive under certain conditions. If you want more control over how connections are handled, you can create restTemplate with HttpComponentsClientHttpRequestFactory
,后者使用 Apache HttpClient
库,例如:
@Bean
RestTemplate restTemplate(SimpleClientHttpRequestFactory factory) {
return new RestTemplate(factory);
}
你也可以在这里看到一些讨论:
How to use RestTemplate efficiently in Multithreaded environment?
我想知道在通过 Spring rest 模板创建新连接之前,HttpConnection 在不活动时保持活动状态多长时间。我查看了默认的连接超时和读取超时参数,但我相信这些是在连接超时的上下文中使用的,当连接由于某些故障等而未建立时。
我正在寻找的是,如果没有 activity(或)不活动,连接将保持活动状态多长时间,以及如何通过 Spring Rest 模板(或)配置它底层机制。
默认情况下 RestTemplate
使用 SimpleClientHttpRequestFactory
进而打开 Java 的 HttpURLConnection
which by default supports keep-alive under certain conditions. If you want more control over how connections are handled, you can create restTemplate with HttpComponentsClientHttpRequestFactory
,后者使用 Apache HttpClient
库,例如:
@Bean
RestTemplate restTemplate(SimpleClientHttpRequestFactory factory) {
return new RestTemplate(factory);
}
你也可以在这里看到一些讨论:
How to use RestTemplate efficiently in Multithreaded environment?