企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
``` public class HttpClientPool { public static void main(String[] args) { PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(100);//最大连接数 cm.setDefaultMaxPerRoute(10);//设置每个主机的最大连接数 doGet(cm); doGet(cm); } private static void doGet(PoolingHttpClientConnectionManager cm){ CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build(); HttpGet httpGet = new HttpGet("http://www.baidu.com"); CloseableHttpResponse response = null; try { response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() == 200){ String content = EntityUtils.toString(response.getEntity(), "utf8"); System.out.println(content); } } catch (IOException e) { e.printStackTrace(); }finally { try { response.close(); }catch (Exception e){ e.printStackTrace(); } } } } ```