作者:wei5xiao5zou6bian6tian | 来源:互联网 | 2023-07-05 11:35
转载地址:https:www.2cto.comkf201710688548.htmlhttpclient版本:4.5.2在项目实际运行中,偶发异常:org.
转载地址: https://www.2cto.com/kf/201710/688548.html
httpclient版本:4.5.2
在项目实际运行中,偶发异常:org.apache.http.NoHttpResponseException。
官网解释是:
In some circumstances, usually when under heavy load, the web server may be able to receive requests but unable to process them. A lack of sufficient resources like worker threads is a good example. This may cause the server to drop the connection to the client without giving any response. HttpClient throws NoHttpResponseException when it encounters such a condition. In most cases it is safe to retry a method that failed with NoHttpResponseException.
修改方案:
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(config)
.setConnectionManager(getPoolManager())
.setRetryHandler((exception, executionCount, context) -> {
if
(executionCount >
3
) {
log.warn(
"Maximum tries reached for client http pool "
);
return
false
;
}
if
(exception
instanceof
NoHttpResponseException
|| exception
instanceof
ConnectTimeoutException
) {
log.warn(
"NoHttpResponseException on "
+ executionCount +
" call"
);
return
true
;
}
return
false
;
})
.build();