What is the meaning of “per route basis” in Poolin

2019-04-19 10:08发布

ThreadSafeClientConnManager is deprecated and a new method is introduced PoolingClientConnectionManager.

The documentation of PoolingClientConnectionManager says

Manages a pool of client connections and is able to service connection requests from multiple execution threads. Connections are pooled on a per route basis.

My Question

What is the meaning of per route basis here?

标签: java apache http
3条回答
Lonely孤独者°
2楼-- · 2019-04-19 10:54

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.

查看更多
Rolldiameter
3楼-- · 2019-04-19 10:59

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

查看更多
你好瞎i
4楼-- · 2019-04-19 11:03

If you wish to understand what a route is (and hence what per-route basis really means) Node.js's express tutorial has a nice reference/description to what a route is. It is a combination of a URI (/URL), a HTTP request method (GET, POST etc), and one or more handlers for the endpoint. Here the "handler" is the function or method that gets executed when you hit the given URL using a specific HTTP request method (like GET etc).

查看更多
登录 后发表回答