httpclientでNoHttpResponseException異常が発生した場合の解決方法


転載先: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())
       // , , retry //  .setRetryHandler(new DefaultHttpRequestRetryHandler(3,true))
       .setRetryHandler((exception, executionCount, context) -> {          if (executionCount > 3 ) {              log.warn( "Maximum tries reached for client http pool " );              return false ;          }
           if (exception instanceof NoHttpResponseException     //NoHttpResponseException                  || exception instanceof ConnectTimeoutException // //              || exception instanceof SocketTimeoutException    // ,                  ) {              log.warn( "NoHttpResponseException on " + executionCount + " call" );              return true ;          }          return false ;      })      .build();