// Create a connection manager with custom configuration.
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
// Create socket configuration
SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).build();// 小数据网络包
// Configure the connection manager to use socket configuration either
// by default or for a specific host.
connManager.setDefaultSocketConfig(socketConfig);
// Validate connections after 1 sec of inactivity
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
// Create socket configuration
SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).build();// 小数据网络包
// Configure the connection manager to use socket configuration either
// by default or for a specific host.
connManager.setDefaultSocketConfig(socketConfig);
// Validate connections after 1 sec of inactivity
connManager.setValidateAfterInactivity(validateInactivityMillSeconds);
这是原先的https管理器的写法,这种写法会默认起一个连接池。
改为 HttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(socketFactoryRegistry);
这样就不会了
本文介绍了如何使用PoolingHttpClientConnectionManager和BasicHttpClientConnectionManager进行HTTP连接管理。通过设置自定义配置,如SocketConfig和验证不活动连接,可以有效地管理和优化HTTP连接。


被折叠的 条评论
为什么被折叠?



