当前位置:网站首页>Resttemplate connection pool configuration
Resttemplate connection pool configuration
2022-07-27 07:40:00 【white_ while】
adopt RestTemplateBuilder Generated by RestTemplate
@Bean(name = "template")
RestTemplate template(RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder
// Company s, Set connection time , Avoid too many threads being blocked and suspended
.setConnectTimeout(Duration.ofSeconds(1))
.setReadTimeout(Duration.ofSeconds(1))
.additionalMessageConverters(new MyMappingJackson2HttpMessageConverter())
.requestFactory(() -> {
HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory();
// Connection pool
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
// Set up HTTP Connection manager
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager();
poolingConnectionManager.setMaxTotal(500); // Maximum number of connections in connection pool
poolingConnectionManager.setDefaultMaxPerRoute(200); // Concurrency per host
httpClientBuilder.setConnectionManager(poolingConnectionManager);
// Set up connection pool
clientHttpRequestFactory.setHttpClient(httpClientBuilder.build());
return clientHttpRequestFactory;
})
.build();
}
restTemplate Connection of by RequestFactory establish
HttpComponentsClientHttpRequestFactory yes RequestFactory Implementation class , Connection pooling , Yes httpClient quote
RestTemplateBuilder Used to generate restTeamplte
configure Method initialized RequestFactory Object passing buildRequestFactory
public ClientHttpRequestFactory buildRequestFactory() {
ClientHttpRequestFactory requestFactory = null;
if (this.requestFactory != null) {
requestFactory = (ClientHttpRequestFactory)this.requestFactory.get();
} else if (this.detectRequestFactory) {
// Default connection pool factory
requestFactory = (new ClientHttpRequestFactorySupplier()).get();
}
if (requestFactory != null && this.requestFactoryCustomizer != null) {
this.requestFactoryCustomizer.accept(requestFactory);
}
return requestFactory;
}
边栏推荐
- STM32_找到导致进入HardFault_Handler的函数
- ADC噪声全面分析 -02- ADC 噪声测量方法和相关参数
- [QT] unable to open the containing file pcap.h (C1083) in QT creator
- Expose Prometheus metrics in Perl programs
- Closed hash and open hash resolve hash conflicts
- Multi condition query of when
- Top ten interview questions for software testing (with answers and analysis)
- Haikang H9 camera cannot be connected with xshell (SSH is not enabled)
- Oracle composite query
- Am I delayed by the code... Unfortunately, I became a programmer
猜你喜欢

电子量产项目框架--基本思想

Top ten interview questions for software testing (with answers and analysis)

基于Arduino的温度、湿度测量显示装置

「翻译」SAP变式物料的采购如何玩转?看看这篇你就明白了

我是不是被代码给耽误了……不幸沦为一名程序员……

js正则表达式实现每三位数字加一个逗号

Single arm routing (explanation + experiment)

C# 中的转译字符'/b'
为啥国内大厂都把云计算当成香饽饽,这个万亿市场你真的了解吗

Clickhouse notes 1 | introduction, features | installation and use based on centos7 system | common data types | mergetree table engine | SQL operation
随机推荐
IO中节点流和处理流的理解学习
Jjwt generate token
Plato farm is expected to further expand its ecosystem through elephant swap
Use shell to calculate the sum of numbers in text
Shell condition test, judgment statement and operator of shell system learning
Showdoc vulnerability learning - cnvd-2020-26585 (arbitrary file upload)
Oracle composite query
flink中维表Join几种常见方式总结
(2022 Niuke multi school III) a-ancestor (LCA)
DASCTF2022.07赋能赛密码wp
C language implementation of guessing numbers Games project practice (based on srand function, rand function, switch statement, while loop, if condition criterion, etc.)
[wsl2] configure the USB camera connecting the USB device and using the host
Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk
Examples of Oracle triggers
Single arm routing (explanation + experiment)
Demonstrate the use of foreign keys with Oracle
连接MySQL时报错:Public Key Retrieval is not allowed 【解决方法】
Flink principle (I) TTL management and fault tolerance mechanism of state
View the dmesg log before server restart
模仿大佬制作的宿舍门禁系统(三)