[英]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 handshake
, tcp 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.