CloseableHttpClient sets Timeout

Set the timeout for CloseableHttpClient

Create a new RequestConfig:

RequestConfig defaultRequestConfig = RequestConfig.custom()
	.setSocketTimeout(5000)  
	.setConnectTimeout(5000)  
	.setConnectionRequestTimeout(5000)  
	.setStaleConnectionCheckEnabled(true)
	.build();

This timeout can be set to the client level as the default for all requests:

CloseableHttpClient httpclient = HttpClients.custom()
    .setDefaultRequestConfig(defaultRequestConfig)
    .build();

Request does not inherit the client-level request configuration, so when customizing the Request, you need to copy the client's default configuration:

HttpGet httpget = new HttpGet("http://www.apache.org/");
RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
.setProxy(new HttpHost("myotherproxy", 8080))
.build();
httpget.setConfig(requestConfig);

Reprinted toOkidoGreen

The article is a memo, do not like to spray, welcome the proposal, thank you.

Intelligent Recommendation

Gin sets Timeout

Original address:https://gist.github.com/montanaflynn/ef9e7b9cd21b355cfe8332b4f20163c1(need to overturn the wall)...

Applet sets request timeout

Configure in app.json...

shiro sets the session timeout

The system default timeout period is 180000 milliseconds (30 minutes) You can set a custom timeout time in the following 2 ways One: Configuration file Two: through api Shiro's Session interface has a...

SpringBoot RestTemplate Sets Timeout

RestTemplate is set for timeout, causing a large amount of Rabbitmq queue, consumers, do not consume, similar thread blockage. Check: From a log quest issue, the business service will be called from e...

More Recommendation

Apache sets a timeout parameter

Add the following code to httpd.conf Modify max_execution_time configuration parameters in php.ini Then restart Apache and PHP....

Springboot sets the timeout period of the RestTemplate

Java config mode Profile specification Designation doc Spring RestTemplate timeout...

Ribbon sets the timeout of the url level

sequence The timeout setting of the ribbon can only be divided according to the forwarded serviceId. It is not possible to set the timeout directly in each forwarded link like nginx. Here hack, implem...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top