0

我使用连接进行服务器连接,如下所示。

    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, 10);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, Integer.valueOf(60000));
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Integer.valueOf(60000));
    params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);

    //eate and initialize scheme registry 
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

    // Create an HttpClient with the ThreadSafeClientConnManager.
    // This connection manager must be used if more than one thread will
    // be using the HttpClient.
    cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    httpClient = new DefaultHttpClient(cm, params);

ThreadSafeClientConnManager API 说:

ThreadSafeClientConnManager maintains a maximum limit of connection on a per route 
basis and in total. Per default this implementation will create no more than than 
2 concurrent connections per given route and no more 20 connections in total. For many 
real-world applications these limits may prove too constraining, especially if they use      
HTTP as a transport protocol for their services. Connection limits, however, can be     
adjusted using HTTP parameters.

如何将每台主机的最大连接数更改为 2 以上?

提前致谢!

4

0 回答 0