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

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

ThreadSafeClientConnManager is deprecated and a new method is introduced PoolingClientConnectionManager.

The documentation of PoolingClientConnectionManager says

<
2条回答
  •  有刺的猬
    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

提交回复
热议问题