HttpClient中的Timout
connection timeout和SoTimeout
A connection timeout occurs only upon starting the TCP connection. This usually happens if the remote machine does not answer. This means that the server has been shut down, you used the wrong IP/DNS name or the network connection to the server is down.
A socket timeout is dedicated to monitor the continuous incoming data flow. If the data flow is interrupted for the specified timeout the connection is regarded as stalled/broken. Of course this only works with connections where data is received all the time.
By setting socket timeout to 1 this would require that every millisecond new data is received (assuming that you read the data block wise and the block is large enough)!
If only the incoming stream stalls for more than a millisecond you are running into a timeout
代码
static final PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager();
static HttpClient getClient() {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(2000)
.setSocketTimeout(2000)
.build();
return HttpClients.custom()
.setConnectionManager(httpClientConnectionManager)
.disableAutomaticRetries()
.setDefaultRequestConfig(requestConfig)
.build();
}
最新文章
- Socket编程——怎么实现一个服务器多个客户端之间的连接
- NHibernate常见问题及解决方法
- silverlight 4.0 的oob模式下,调用com通过wmi重启自身进程 killself
- UEditor百度编辑器,工具栏上自定义添加一个普通按钮
- Oracle 表空间联机(online)与脱机(offline)
- BrowserSync前端调试工具使用
- Shell 条件表达式汇总
- 8款实用的Jquery瀑布流插件
- 理解js中的原型链,prototype与__proto__的关系
- python——快速找出两个电子表中数据的差异
- _beginthread和CreatThread的区别
- R语言实战(二)——数据分析基础知识
- 【UML】NO.55.EBook.8.UML.3.001-【UML和模式应用 第3版】
- echarts双y轴折线图柱状图混合实时更新图
- linux下应用程序性能剖分神器gprofiler-tools-安装和使用
- 青蛙跳台阶(C、Python)
- [Python]编码声明:是coding:utf-8还是coding=urf-8呢
- 【8】python文件的读写方法
- Intro to Python for Data Science Learning 2 - List
- 【WCF】HTTP 无法注册 URL 进程,不具有此命名空间的访问权限