JasionL
JasionL
2017-10-10 09:22
采纳率: 50%
浏览 2.4k
已采纳

httpclient怎么设置连接池连接等待时间

连接满时,会处于连接池等待状态,怎么设置连接池等待时间,避免造成长时间等待
求大神解答,急!在线等!!!!

/*读取超时*/
private final static int SOCKET_TIMEOUT = 50000;
/*连接超时*/
private final static int CONNECTION_TIMEOUT = 50000;
/*每个HOST的最大连接数量*/
private final static int MAX_CONN_PRE_HOST = 2;
/*连接池的最大连接数*/
private final static int MAX_CONN = 60;
/*连接池*/
private final static HttpConnectionManager httpConnectionManager;

static{     
    httpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = httpConnectionManager.getParams();
    params.setConnectionTimeout(CONNECTION_TIMEOUT);
    params.setSoTimeout(SOCKET_TIMEOUT);
    params.setDefaultMaxConnectionsPerHost(MAX_CONN_PRE_HOST);
    params.setMaxTotalConnections(MAX_CONN);

}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • lockemn
    lockemn 2017-10-10 10:12
    已采纳

    HttpClient在连接不够用的时候,**连接池等待超时时间**设置:

    HttpClientParams httpClientParams = new HttpClientParams();
    httpClientParams.**setConnectionManagerTimeout**(3000);
    httpClient.setParams(httpClientParams);

    
    
    点赞 评论
  • JasionL
    JasionL 2017-10-10 09:41

    没有悬赏都没人回答吗?

    点赞 评论
  • qq_20640443
    qq_20640443 2017-10-10 13:42

    HttpClient在连接不够用的时候,**连接池等待超时时间**设置:

    HttpClientParams httpClientParams = new HttpClientParams();
    httpClientParams.**setConnectionManagerTimeout**(3000);
    httpClient.setParams(httpClientParams);

    点赞 评论

相关推荐