HttpAsyncClient

前端之家收集整理的这篇文章主要介绍了HttpAsyncClient前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

HttpAsyncClient 简单实例

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOReactorException;

/**

  • 异步http客户端
  • */

public class AsyncClient {

private static int MAX_CONN_COUNT = 20000;
private static CloseableHttpAsyncClient asyncClient;

static {
ConnectingIOReactor ioReactor;
try {
ioReactor = new DefaultConnectingIOReactor();
} catch (IOReactorException e) {
throw new RuntimeException(e);
}
PoolingNHttpClientConnectionManager cm = new PoolingNHttpClientConnectionManager(ioReactor);
cm.setMaxTotal(MAX_CONN_COUNT);
cm.setDefaultMaxPerRoute(MAX_CONN_COUNT);
asyncClient = HttpAsyncClients.custom().setConnectionManager(cm).build();
asyncClient.start();
}

public static CloseableHttpAsyncClient getInstance() {
return asyncClient;
}
}

猜你在找的程序笔记相关文章