![](/img/trans.png)
[英]PoolingHttpClientConnectionManager does not release connections
[英]How PoolingHttpClientConnectionManager manage connections?
我有一个问题,它是What is httpconnection of PoolingHttpClientConnectionManager?.
我知道如果我们使用PoolingHttpClientConnectionManager
,它减少了花费连接建立的时间(例如ssl handshake
, tcp enter code herehandshake
等),因为它重用了连接。
但是,我对 http 连接重用的理解是保持活动状态,我们可以在服务器支持时使用它。 如果主机不支持keep-alive 连接,我们就无法与带有keep-alive 的主机通信。
所以,这是我的问题,
如果我使用 PoolingHttpClientConnectionManager 管理非保持活动服务器环境中的连接,Connectionmanager 是否管理连接? 或者它根据请求创建连接?
如果 ConnectionManager 管理连接,ConnectionManager 如何保持连接? 管理器是否定期发送字节?
如果你没有定义 HttpClient 将作为连接可以无限期地保持活动状态,来自Apache http docs :
如果响应中不存在 Keep-Alive 标头,则 HttpClient 假定连接可以无限期地保持活动状态。
如果要定义 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.