代码片段: PoolingHttpClientConnectionManager的使用-PoolingHttpClientConnectionManager的使用

package com.github.liyiorg.common.api; import org.apache.http.config.SocketConfig; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.H...
<pre>package com.github.liyiorg.common.api; import org.apache.http.config.SocketConfig; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; public abstract class BaseAPI { protected static CloseableHttpClient httpClient; static{ PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(); poolingHttpClientConnectionManager.setMaxTotal(100); poolingHttpClientConnectionManager.setDefaultMaxPerRoute(10); SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(1000*5).build(); poolingHttpClientConnectionManager.setDefaultSocketConfig(socketConfig); httpClient = HttpClientBuilder.create() .setConnectionManager(poolingHttpClientConnectionManager) .disableCookieManagement() .build(); } } </pre>
  • 发表于 2018-07-07 19:40
  • 阅读 ( 685 )
  • 分类:代码片段

条评论

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

篇文章

作家榜 »

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