简体   繁体   中英

How to set timeout for each request using Apache httpclient 4.* with PoolingHttpClientConnectionManager?

How to use the Apache httpclient 4.3 and PoolingHttpClientConnectionManager and pass the ConnectTimeOut and ReadTimeOut for each request.

For example, If I have the CloseableHttpClient as Singleton and using the PoolingHttpClientConnection to obtain the connection, for each request I make , I want to send different timeout values based on the target host

ie. HostA 10 Seconds , Host B 5 seconds etc

Please advise.

HttpGet get1 = new HttpGet("http://hosta/");
RequestConfig config1 = RequestConfig.custom().setSocketTimeout(10000).build();
get1.setConfig(config1);
HttpGet get2 = new HttpGet("http://hostb/");
RequestConfig config2 = RequestConfig.custom().setSocketTimeout(5000).build();
get2.setConfig(config2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM