繁体   English   中英

使用HttpClient同时处理两个以上的请求

[英]Handle more then two requests simultaneously with HttpClient

每当我在Spring Boot的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);

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM