简体   繁体   English

PoolingHttpClientConnectionManager 如何管理连接?

[英]How PoolingHttpClientConnectionManager manage connections?

I have a question and it is What is httpconnection of PoolingHttpClientConnectionManager?.我有一个问题,它是What is httpconnection of PoolingHttpClientConnectionManager?.

I know that If we use PoolingHttpClientConnectionManager , it reduces the time for spending connection establishment (such as ssl handshake , tcp enter code herehandshake etc) because it reuses the connections.我知道如果我们使用PoolingHttpClientConnectionManager ,它减少了花费连接建立的时间(例如ssl handshaketcp enter code herehandshake等),因为它重用了连接。

However, what I understand about http connection reusing is keep-alive and we can use it when server support it.但是,我对 http 连接重用的理解是保持活动状态,我们可以在服务器支持时使用它。 If host doesn't support keep-alive connection, we cannot communicate with the host with keep-alive.如果主机不支持keep-alive 连接,我们就无法与带有keep-alive 的主机通信。

So, here are my questions,所以,这是我的问题,

If I use PoolingHttpClientConnectionManager to manage connections on non keep-alive server environment, does Connectionmanager manage connections?如果我使用 PoolingHttpClientConnectionManager 管理非保持活动服务器环境中的连接,Connectionmanager 是否管理连接? or it creates connection per request?或者它根据请求创建连接?

If ConnectionManager manages connections, how ConnectionManager keep connection?如果 ConnectionManager 管理连接,ConnectionManager 如何保持连接? does the manager send bytes periodically?管理器是否定期发送字节?

If you don't define HttpClient will act as connection can be kept alive indefinitely, from Apache http docs :如果你没有定义 HttpClient 将作为连接可以无限期地保持活动状态,来自Apache http docs

If the Keep-Alive header is not present in the response, HttpClient assumes the connection can be kept alive indefinitely.如果响应中不存在 Keep-Alive 标头,则 HttpClient 假定连接可以无限期地保持活动状态。

If you want to define Keep-Alive Strategy see example :如果要定义 Keep-Alive 策略,请参见示例

ConnectionKeepAliveStrategy myStrategy = new ConnectionKeepAliveStrategy() {
    @Override
    public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
        HeaderElementIterator it = new BasicHeaderElementIterator
            (response.headerIterator(HTTP.CONN_KEEP_ALIVE));
        while (it.hasNext()) {
            HeaderElement he = it.nextElement();
            String param = he.getName();
            String value = he.getValue();
            if (value != null && param.equalsIgnoreCase
               ("timeout")) {
                return Long.parseLong(value) * 1000;
            }
        }
        return 5 * 1000;
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PoolingHttpClientConnectionManager不释放连接 - PoolingHttpClientConnectionManager does not release connections 如何使用PoolingHttpClientConnectionManager限制同一主机(setMaxPerRoute)的连接? - How to to limit connections for the same host (setMaxPerRoute) using PoolingHttpClientConnectionManager? 使用 PoolingHttpClientConnectionManager 获取重用连接的统计信息 - Get stats of reused connections with PoolingHttpClientConnectionManager 为什么PoolingHttpClientConnectionManager提供越来越慢的连接? - Why is PoolingHttpClientConnectionManager providing increasingly slow connections? 如何在PoolingHttpClientConnectionManager中设置setMaxPerRoute? - How to set setMaxPerRoute in PoolingHttpClientConnectionManager? 如何正确管理MySQL连接? - How to manage MySQL Connections properly? PoolingHttpClientConnectionManager:如何做Https请求? - PoolingHttpClientConnectionManager: How to do Https requests? 我该如何管理Android中的蓝牙连接? - How should I manage Bluetooth connections in Android? spring 如何管理与数据库的大量连接? - spring how to manage lots connections to database? 如何管理与动态创建的数据库的连接 - how to manage connections to dynamically created databases
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM