本文整理汇总了Java中org.apache.http.impl.conn.PoolingHttpClientConnectionManager.closeExpiredConnections方法的典型用法代码示例。如果您正苦于以下问题:Java PoolingHttpClientConnectionManager.closeExpiredConnections方法的具体用法?Java PoolingHttpClientConnectionManager.closeExpiredConnections怎么用?Java PoolingHttpClientConnectionManager.closeExpiredConnections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.conn.PoolingHttpClientConnectionManager
的用法示例。
在下文中一共展示了PoolingHttpClientConnectionManager.closeExpiredConnections方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
@Override
public void run() {
try {
log.debug("Starting Gems Idle Connection Monitor Thread ");
while (!shutdown) {
synchronized (this) {
wait(10000);
if (!connMgrList.isEmpty()) {
for (PoolingHttpClientConnectionManager connPollMgr : connMgrList) {
connPollMgr.closeExpiredConnections();
}
}
}
}
} catch (InterruptedException ex) {
log.debug("Terminating Gems Idle Connection Monitor Thread ");
}
}
示例2: createClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private CloseableHttpClient createClient() {
try {
final SSLContext sslcontext = SSLContexts.custom().useProtocol("TLSv1.2").build();
SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslcontext) {
@Override
public Socket createLayeredSocket(
final Socket socket,
final String target,
final int port,
final HttpContext context) throws IOException {
context.setAttribute("__enable_sni__", true);
return super.createLayeredSocket(socket, target, port, context);
}
};
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sslConnectionFactory)
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.build();
PoolingHttpClientConnectionManager poolingHttpClientConnectionManager =
new PoolingHttpClientConnectionManager(registry);
poolingHttpClientConnectionManager.closeExpiredConnections();
poolingHttpClientConnectionManager
.closeIdleConnections((timeout != null) ? timeout : DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
RequestConfig requestConfig = RequestConfig
.custom().setConnectTimeout((timeout != null) ? timeout : DEFAULT_TIMEOUT)
.setConnectionRequestTimeout((timeout != null) ? timeout : DEFAULT_TIMEOUT)
.setSocketTimeout((timeout != null) ? timeout : DEFAULT_TIMEOUT)
.build();
httpClient = HttpClients.custom().setConnectionManager(poolingHttpClientConnectionManager)
.setDefaultRequestConfig(requestConfig).build();
} catch (Exception ex) {
httpClient = HttpClients.createDefault();
}
return httpClient;
}