Java PoolighttpClientConnectionManager如何管理连接?
我有一个问题,它是Java PoolighttpClientConnectionManager如何管理连接?,java,connection-pooling,keep-alive,httpconnection,apache-httpcomponents,Java,Connection Pooling,Keep Alive,Httpconnection,Apache Httpcomponents,我有一个问题,它是什么是poolighttpclientconnectionmanager的httpconnection? 我知道,如果我们使用poolighttpclientconnectionmanager,它会减少建立连接的时间(例如ssl握手,tcp在此处输入代码握手等),因为它会重用连接 然而,我对http连接重用的理解是保持活动状态,当服务器支持它时,我们可以使用它。如果主机不支持keep-alive连接,则无法使用keep-alive与主机通信 所以,这里是我的问题 如果我使用Po
什么是poolighttpclientconnectionmanager的httpconnection?
我知道,如果我们使用poolighttpclientconnectionmanager
,它会减少建立连接的时间(例如ssl握手
,tcp在此处输入代码握手
等),因为它会重用连接
然而,我对http连接重用的理解是保持活动状态,当服务器支持它时,我们可以使用它。如果主机不支持keep-alive连接,则无法使用keep-alive与主机通信
所以,这里是我的问题
如果我使用PoollightTPClientConnectionManager来管理非保持活动的服务器环境上的连接,
Connectionmanager是否管理连接?或者它根据请求创建连接
如果ConnectionManager管理连接,那么ConnectionManager如何保持连接?管理器是否定期发送字节?如果您不定义HttpClient,它将充当连接,可以无限期保持活动状态,从: 如果响应中不存在Keep-Alive标头,则HttpClient 假设连接可以无限期保持活动状态 如果要定义“保持活力”策略,请参阅:
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;
}
};