What is the meaning of “per route basis” in PoolingClientConnectionManager?

前端 未结 2 774
[愿得一人]
[愿得一人] 2021-02-19 04:55

ThreadSafeClientConnManager is deprecated and a new method is introduced PoolingClientConnectionManager.

The documentation of PoolingClientConnectionManager says

<
相关标签:
2条回答
  • 2021-02-19 05:40

    Put it in simple term, per route means per host you are connecting to.

    PoolingHttpClientConnectionManager maintains a maximum limit of connections on a per route basis and in total. Per default this implementation will create no more than 2 concurrent connections per given route and no more 20 connections in total.

    0 讨论(0)
  • 2021-02-19 06:00

    It refers to the HttpRoute. The HttpRoute is to delineate multiple applications running on the same web server.

    http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/conn/routing/HttpRoute.html

    It is used like below:

    ClientConnectionRequest connRequest = connMrg.requestConnection(
            new HttpRoute(new HttpHost("localhost", 80)), null);
    ManagedClientConnection conn = connRequest.getConnection(10, TimeUnit.SECONDS);
    try {
        BasicHttpRequest request = new BasicHttpRequest("GET", "/");
        conn.sendRequestHeader(request);
        HttpResponse response = conn.receiveResponseHeader();
        conn.receiveResponseEntity(response);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            BasicManagedEntity managedEntity = new BasicManagedEntity(entity, conn, true);
            // Replace entity
            response.setEntity(managedEntity);
        }
        // Do something useful with the response
        // The connection will be released automatically 
        // as soon as the response content has been consumed
    } catch (IOException ex) {
        // Abort connection upon an I/O error.
        conn.abortConnection();
        throw ex;
    }
    

    source: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html

    0 讨论(0)
提交回复
热议问题