NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
``` 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(); } } } } ```