CloseableHttpClient 在使用过程中遇到的问题
代码是前辈写的,在对代码进行压测的时候遇到了个问题,最大线程是 不能超过setDefaultMaxPerRoute设置的数字,一点超过 就会死掉。这里会报错 connection pool shut down httpclient
查找过很多博客,查到原因是因为接受到的集合没有释放导致 CloseableHttpClient 一直在被占用。随意可使用的最线程数 就不会超过 之前设置setDefaultMaxPerRoute 数字
private
static
CloseableHttpClienthttpClient;
static
{
PoolingHttpClientConnectionManagercm =
new
PoolingHttpClientConnectionManager();
cm.setMaxTotal(
200
);
cm.setDefaultMaxPerRoute(
20
);
cm.setDefaultMaxPerRoute(
50
);
httpClient = HttpClients.custom().setConnectionManager(cm).build();
}
public
static
String get(String url) {
HttpResponse response
=
null
;
BufferedReaderin =
null
;
String result =
""
;
try
{
HttpGethttpGet =
new
HttpGet(url);
response = httpClient.execute(httpGet);
in =
new
BufferedReader(
new
InputStreamReader(response.getEntity().getContent()));
StringBuffersb =
new
StringBuffer(
""
);
String line =
""
;
String NL = System.getProperty(
"line.separator"
);
while
((line = in.readLine()) !=
null
) {
sb.append(line + NL);
}
in.close();
result = sb.toString();
}
catch
(IOException e) {
e.printStackTrace();
}
return
result;
}
public
static
void
main(String[] args) {
System.out.println(get(
"https://www.baidu.com/"
));
}
public
static
String get(String url) {
CloseableHttpResponse response
=
null
;
BufferedReaderin =
null
;
String result =
""
;
try
{
HttpGethttpGet =
new
HttpGet(url);
response = httpClient.execute(httpGet);
in =
new
BufferedReader(
new
InputStreamReader(response.getEntity().getContent()));
StringBuffersb =
new
StringBuffer(
""
);
String line =
""
;
String NL = System.getProperty(
"line.separator"
);
while
((line = in.readLine()) !=
null
) {
sb.append(line + NL);
}
in.close();
result = sb.toString();
}
catch
(IOException e) {
e.printStackTrace();
}
finally
{
try
{
if
(
null
!= response) response.close();
}
catch
(IOException e) {
e.printStackTrace();
}
}
return
result;
}
return
result;
}
public
static
void
main(String[] args) {
System.out.println(get(
"https://www.baidu.com/"
));
}
转载于:https://www.cnblogs.com/hugo-zhangzhen/p/6858013.html
CloseableHttpClient 在使用过程中遇到的问题相关推荐
- 总结一下在使用某里云服务器的过程中出现过的一些问题
此文总结在使用阿里云的过程中出现过的问题 想起来就记录一下 本人为言行负责! 海内选择腾讯华为,共勉! k8s不同命名空间的配置文件串掉了 k8s集群服务器购买上后,无法使用外网.连续购买了4台然 ...
- OpenCV 相机校正过程中,calibrateCamera函数projectPoints函数的重投影误差的分析
OpenCV 校正过程中,calibrateCamera函数的ret和重投影误差的分析 OpenCV对相机进行校正的过程中,校正返回值retval和重投影误差的计算公式表示和分析. OpenCV 校正 ...
- 理解YOLOv2训练过程中输出参数含义
转载自https://blog.csdn.net/dcrmg/article/details/78565440 原英文地址: https://timebutt.github.io/static/und ...
- 计算机视觉:Bag of words算法实现过程中出现错误及解决方案
Bag of words算法实现过程中出现错误及解决方案 出现的问题 IndexError: list index out of range OSError:x.sift not found sqli ...
- as安装过程中gradle_柯赛分享:楼顶大字安装过程中需要用到哪些工具?
经过前面一系列标识行业常识和制作工艺相关知识的分享,我们知道楼顶大字是标识行业下属的一个重要分支产品类别,也明白了楼顶大字主要制作材料是金属的,尺寸和自重都比较大,运输安装过程相对复杂,安装施工的难度 ...
- C++中stl使用过程中的一些tips
该博文整理一些在使用stl编程过程中遇到的小经验: 1.在多线程环境下面打印调试,如何使用cout及时刷新到屏幕上? 在C中我们经常这样使用: printf("Hello World\n&q ...
- 关于部署osd过程中:Device is in use by a device-mapper mapping问题解决
ceph环境:12.2.1 使用古老的ceph-disk工具部署osd,仅仅prepare过程中就出现如上所示问题 Device is in use by a device-mapper mappin ...
- Oracle EBS R12 运行adadmin 安装中文语言包过程中意外中断后的处理
介绍Oracle EBS R12 运行adadmin 安装中文语言包过程中意外中断后的处. Oracle EBS R12 运行adadmin 安装中文语言包过程中意外中断或关机后,重新开机,运行数据库 ...
- oracle里面子判断,在过程中添加子进程,在子过程中判断
在过程中添加子过程,在子过程中判断 本帖最后由 wu_xiao_xian 于 2014-10-28 15:23:03 编辑 现在有一个过程BI_OSS_SHOULD_CALL_P DROP PROCE ...
- mysql8 my 010457_分享一下我在mysql5.6+mysql8数据库安装过程中的一些坑!
Mysql5.6安装 下载好安装包后,在bin目录下用cmd打开,输入mysqld install [服务名]新建个服务 在windows+r输入services.msc即可查看服务 怎样使用mysq ...
最新文章
- leetcode-155 最小栈
- 二本学生连发10篇SCI直博香港城大,被质疑「灌水」,本人回应!
- make: warning: file “xxx“ has modification time yyy s in the future 解决方法
- 点(Dot)与像素(Pixel)的区别
- php中$_get和$_post如何使用,怎么使用超级全局变量$_POST与$_GET
- python蚁群算法 路径规划_蚁群算法(1) - Python实现
- 如何在symfony 控制器里面创建soap web service
- Linux环境下Lapack软件包的编译和使用
- moss 搜索 属性过滤 值被移除了
- HTML和小程序的 12 种 flex 布局
- python爬取网页题库_用Python爬取本站离线题库
- 程序员如何预防颈椎病?
- SpringMVC+Mybatis框架集成开发基础——项目开发流程——01
- 如何为SSH登录建立双因子验证机制(谷歌身份验证器)?
- 尚医通 (二十)就诊人用户管理 | 平台用户管理
- 汽车网络安全之——CAN网关测试
- 昆兰士科技大学计算机排名,2019上海软科世界一流学科排名计算机科学与工程专业排名昆士兰科技大学排名第151-200...
- edge黑色主题/夜间模式(包括页面也是)
- 2021消防设施操作员(中级)岗位考试模拟题库判断自动系统知识部分
- AIX 如何在 IBM AIX 上配置 YUM 并创建本地存储库
热门文章
- [渝粤教育] 中国地质大学 事故应急救援 复习题 (2)
- 软件类配置(二)【Windows中安装python、pycharm、opencv、anaconda】
- leetcode第一刷_Merge Intervals
- FJUT 2351 T^T的图论(并查集)
- jsp中9个内置对象与servlet对应关系及四个作用域
- ORACLE TRUNC()函数
- thinkphp 5.0 模块设计
- BaseAdapter的逗逼、普通、文艺写法
- 输出NSRange类型的数据
- Windows Phone 7 MVVM模式的学习笔记