设置Apache的HttpClient请求时间超时
2014-12-02 13:10
706 查看
用Apache的HttpClient请求Http连接时,如果第三方返回的时候过长,导致影响现有服务的业务。可以设置请求Http第三方时的超时时间。
当超过指定时间时,HttpClient会自动断开链接并抛出IOException异常
RequestConfig defaultRequestConfig = RequestConfig.custom().setConnectTimeout(getHttpTimeout()).setSocketTimeout(getHttpTimeout())
.setConnectionRequestTimeout(getHttpTimeout()).setStaleConnectionCheckEnabled(true).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(defaultRequestConfig).build();
protected int getHttpTimeout() {
return this.httpTimeout;
}
当超过指定时间时,HttpClient会自动断开链接并抛出IOException异常
RequestConfig defaultRequestConfig = RequestConfig.custom().setConnectTimeout(getHttpTimeout()).setSocketTimeout(getHttpTimeout())
.setConnectionRequestTimeout(getHttpTimeout()).setStaleConnectionCheckEnabled(true).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(defaultRequestConfig).build();
protected int getHttpTimeout() {
return this.httpTimeout;
}
相关文章推荐
- Apache HttpClient设置请求超时时间和返回超时时间,以及超时重试
- HttpClientUtils.post不设置超时时间容易导致,请求无法返回
- Apache HttpClient调用服务没有设置超时时间引起的血崩
- apache httpclient4 设置超时时间
- httpclient发送http请求设置网络超时时间
- 使用HttpURLConnection设置请求超时时间,请求超时时会导致自动重发。
- org.apache.commons.httpclient.HttpClient 设置数据接收超时
- HttpClient连接请求超时设置
- 设置DefaultHttpClient和HttpClient的超时时间的方法
- 为ServerXMLHTTP对象的HTTP请求设置超时时间
- HttpClient 4.5.2版本设置连接超时时间-CloseableHttpClient设置Timeout
- go http.Get请求 http.Post请求 http.PostForm请求 Client 超时设置
- HttpClient请求时connectionRequestTimeout 、connectionTimeout、socketTimeout三个超时时间的含义
- 为ServerXMLHTTP对象的HTTP请求设置超时时间
- cxf和HttpClient调用WebService,并设置超时时间
- http 请求 超时时间设置
- HttpClient 4.5版本设置连接超时时间
- HttpClient 4.5版本设置连接超时时间
- httpClient 超时时间设置(转)
- 为ServerXMLHTTP对象的HTTP请求设置超时时间