您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

获取NoHttpResponseException以进行负载测试

获取NoHttpResponseException以进行负载测试

我找到了问题的根本原因。

由于某种原因,连接变为无效,并且池不知道该连接。

在这种情况下,NoHttpResponseException将引发且请求仅失败。我认为此类问题应在HTTP客户端池层中解决,并且对我的代码是透明的,但事实并非如此。

解决此问题HttpRequestRetryHandler,HTTP客户端应被覆盖:

ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
...
DefaultHttpClient httpClient = new DefaultHttpClient(cm, params);
httpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
    @Override
    public boolean retryRequest(IOException exception, int executionCount, 
                                HttpContext context) {
        if (executionCount > 3) {
           LOGGER.warn("Maximum tries reached for client http pool ");
                return false;
        }
        if (exception instanceof org.apache.http.NoHttpResponseException) {
            LOGGER.warn("No response from server on " + executionCount + " call");
            return true;
        }
        return false;
      }
   });
其他 2022/1/1 18:13:48 有539人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶