java类org.apache.http.impl.client.DefaultBackoffStrategy的实例源码

SnowizardClient.java 文件源码 项目:snowizard 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Get a new CloseableHttpClient
 * 
 * @return CloseableHttpClient
 */
public static CloseableHttpClient newHttpClient() {
    final SocketConfig socketConfig = SocketConfig.custom()
            .setSoKeepAlive(Boolean.TRUE).setTcpNoDelay(Boolean.TRUE)
            .setSoTimeout(SOCKET_TIMEOUT_MS).build();

    final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();
    manager.setDefaultMaxPerRoute(MAX_HOSTS);
    manager.setMaxTotal(MAX_HOSTS);
    manager.setDefaultSocketConfig(socketConfig);

    final RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(CONNECTION_TIMEOUT_MS)
            .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .setStaleConnectionCheckEnabled(Boolean.FALSE)
            .setSocketTimeout(SOCKET_TIMEOUT_MS).build();

    final CloseableHttpClient client = HttpClients
            .custom()
            .disableRedirectHandling()
            .setConnectionManager(manager)
            .setDefaultRequestConfig(requestConfig)
            .setConnectionReuseStrategy(
                    new DefaultConnectionReuseStrategy())
            .setConnectionBackoffStrategy(new DefaultBackoffStrategy())
            .setRetryHandler(
                    new DefaultHttpRequestRetryHandler(MAX_RETRIES, false))
            .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy())
            .build();
    return client;
}


问题


面经


文章

微信
公众号

扫码关注公众号