简体   繁体   English

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

[英]Handle more then two requests simultaneously with HttpClient

Whenever I have the following calls in one getmapping method in my restcontroller made in Spring boot, it never gets executed. 每当我在Spring Boot的restcontroller中的一个getmapping方法中使用以下调用时,就永远不会执行。 It works perfectly when I comment out one out of the three. 当我注释掉三个中的一个时,它非常有效。 It doesn't matter which combination, they all work but maximum with two. 不管是哪种组合,它们都可以工作,但最多只能有两个。

        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);

The connection pool for Apache's HttpClient can by default only have two connections open at the same time. 默认情况下,Apache HttpClient的连接池只能同时打开两个连接。

To be able to execute more requests it is mandatory to close the response objects in order to release a connection to the pool again. 为了能够执行更多请求,必须关闭响应对象才能再次释放与池的连接。

More information can be found here: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html 可以在这里找到更多信息: 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