当前位置: 首页>>代码示例>>Java>>正文


Java PoolingHttpClientConnectionManager.closeExpiredConnections方法代码示例

本文整理汇总了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 ");
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:19,代码来源:RepositoryServiceImpl.java

示例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;
    }
 
开发者ID:americanexpress,项目名称:amex-api-java-client-core,代码行数:42,代码来源:ApiClient.java


注:本文中的org.apache.http.impl.conn.PoolingHttpClientConnectionManager.closeExpiredConnections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。