PoolingClientConnectionManager中"per route basis"的含义是什么?

Gau*_*wal 14 java apache http

不推荐使用ThreadSafeClientConnManager,并引入了一个新方法PoolingClientConnectionManager.

PoolingClientConnectionManager的文档说

管理客户端连接池,并且能够为来自多个执行线程的连接请求提供服务.连接以每个路由为基础进行池化.

我的问题

这里每条路线的含义是什么?

sen*_*982 9

简单来说,每个路由意味着您连接到的每个主机.

PoolingHttpClientConnectionManager维护每个路由和总计的最大连接数限制.默认情况下,此实现将为每个给定路由创建不超过2个并发连接,并且总共不再有20个连接.


sri*_*lla 4

它指的是HttpRoute。HttpRoute 是为了描绘在同一个 Web 服务器上运行的多个应用程序。

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

它的用法如下:

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;
}
Run Code Online (Sandbox Code Playgroud)

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

  • 用更简单的语言进行更多解释将使答案对更广泛的受众有用。 (10认同)