Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java CloseableHttpClient连接池关闭_Java_Httpclient - Fatal编程技术网

Java CloseableHttpClient连接池关闭

Java CloseableHttpClient连接池关闭,java,httpclient,Java,Httpclient,当我使用CloseableHttpClient和do Execute方法时,它在第一次正常工作,但之后从未成功。 它将抛出表示“连接池关闭”的异常 有人这么说是因为我没有关闭客户 有人说这是httpclient 4.3中的一个bug 我的项目不存在上述问题,但仍然无法正常工作 CloseableHttpClient httpClient = HttpClientManagerUtils.getHttpClient(); try { HttpResponse respon

当我使用CloseableHttpClient和do Execute方法时,它在第一次正常工作,但之后从未成功。 它将抛出表示“连接池关闭”的异常

有人这么说是因为我没有关闭客户 有人说这是httpclient 4.3中的一个bug

我的项目不存在上述问题,但仍然无法正常工作

CloseableHttpClient httpClient = HttpClientManagerUtils.getHttpClient();

    try {
        HttpResponse response = httpClient.execute(httpPost);
        if (response.getStatusLine().getStatusCode() == 200) {
            log.info("调用网易接口成功,url:{},param:{}", url, JSONObject.toJSON(param));
            HttpEntity entity = response.getEntity();
            if (entity.getContentType().toString().contains("application/json")) {
                String responseString = EntityUtils.toString(entity, "utf-8");
                return JSON.toJavaObject(JSON.parseObject(responseString), NimResult.class);
            }
        } else {
            throw new RuntimeException("http code : " + response.getStatusLine().getStatusCode() + ", exception:" +
                    EntityUtils.toString(response.getEntity()));
        }
    } catch (Exception e) {
        log.error("调用网易接口异常,url:{},param:{}", url, JSONObject.toJSON(param), e);
    } finally {
        httpClient.close();
    }

我不应该关闭客户端,而是应该关闭响应。自httpclient 4.4起,客户将自动关闭 我已经解决了:)