我正在使用Apache Http Client,并且想知道在响应时间> 3000毫秒的情况下使用哪个API来设置超时。
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.1.4</version>
</dependency>
以下是我当前的代码-
RequestConfig requestConfig = RequestConfig.custom().build();
// Create I/O reactor configuration
IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
.setIoThreadCount(ioThreads)
.setSoKeepAlive(true)
.build();
// Create a custom I/O reactort
ConnectingIOReactor ioReactor = null;
try {
ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
} catch (IOReactorException e) {
e.printStackTrace();
}
PoolingNHttpClientConnectionManager poolingConnectionManager = new PoolingNHttpClientConnectionManager(ioReactor);
poolingConnectionManager.setMaxTotal(mc);
poolingConnectionManager.setDefaultMaxPerRoute(mc);
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setConnectionManager(poolingConnectionManager)
.setDefaultRequestConfig(requestConfig)
.build();