代码片段: PoolingHttpClientConnectionManager的使用-PoolingHttpClientConnectionManager

package com.dipub.http; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingH...
<pre>package com.dipub.http; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; @Component @Configuration public class HttpClientManager { @Bean(name = "poolingHttpClientConnectionManager") public PoolingHttpClientConnectionManager poolingHttpClientConnectionManager() { PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(); poolingHttpClientConnectionManager.setMaxTotal(200); poolingHttpClientConnectionManager.setDefaultMaxPerRoute(50); return poolingHttpClientConnectionManager; } @Bean(name = "httpClientBuilder") public HttpClientBuilder httpClientBuilder() { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); httpClientBuilder.setConnectionManager(poolingHttpClientConnectionManager()); return httpClientBuilder; } @Bean(name = "httpClient") public CloseableHttpClient httpClient() { return httpClientBuilder().build(); } }</pre>
  • 发表于 2018-07-07 19:40
  • 阅读 ( 555 )
  • 分类:代码片段

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除