使用HttpClient

时间:2019-02-19 11:56:34

标签: java spring controller servicenow-rest-api

每当我在Spring引导的restcontroller中的一个getmapping方法中进行以下调用时,就永远不会执行。 当我注释掉三个中的一个时,它非常有效。 不管是哪种组合,它们都可以工作,但最多只能有两个。

        HttpGet httpget1 = new HttpGet(url+"api/now/table/incident?assignment_group=FS_logistic&incident_state=1");
        httpget1.setHeader("Accept", "application/json");
        CloseableHttpResponse response1 = httpclient.execute(httpget1);

        HttpGet httpget2 = new HttpGet(url+"api/now/table/incident?assignment_group=FS_logistic&incident_state=2");
        httpget2.setHeader("Accept", "application/json");
        CloseableHttpResponse response2 = httpclient.execute(httpget2);


        HttpGet httpget3 = new HttpGet(url+"api/now/table/incident?assignment_group=FS_logistic&incident_state=3");
        httpget3.setHeader("Accept", "application/json");
        CloseableHttpResponse response3 = httpclient.execute(httpget3);

1 个答案:

答案 0 :(得分:0)

默认情况下,Apache HttpClient的连接池只能同时打开两个连接。

为了能够执行更多请求,必须关闭响应对象才能再次释放与池的连接。

更多信息可以在这里找到: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html