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

最新文章

  1. Socket编程——怎么实现一个服务器多个客户端之间的连接
  2. NHibernate常见问题及解决方法
  3. silverlight 4.0 的oob模式下,调用com通过wmi重启自身进程 killself
  4. UEditor百度编辑器,工具栏上自定义添加一个普通按钮
  5. Oracle 表空间联机(online)与脱机(offline)
  6. BrowserSync前端调试工具使用
  7. Shell 条件表达式汇总
  8. 8款实用的Jquery瀑布流插件
  9. 理解js中的原型链,prototype与__proto__的关系
  10. python——快速找出两个电子表中数据的差异
  11. _beginthread和CreatThread的区别
  12. R语言实战(二)——数据分析基础知识
  13. 【UML】NO.55.EBook.8.UML.3.001-【UML和模式应用 第3版】
  14. echarts双y轴折线图柱状图混合实时更新图
  15. linux下应用程序性能剖分神器gprofiler-tools-安装和使用
  16. 青蛙跳台阶(C、Python)
  17. [Python]编码声明:是coding:utf-8还是coding=urf-8呢
  18. 【8】python文件的读写方法
  19. Intro to Python for Data Science Learning 2 - List
  20. 【WCF】HTTP 无法注册 URL 进程,不具有此命名空间的访问权限

热门文章

  1. 【BestCoder】【Round#44】
  2. C++11学习
  3. Callable、Future&阻塞队列&阻塞栈
  4. 使用Gnupg对Linux系统中的文件进行加密
  5. xshell实现端口转发
  6. 有关String的转换的一篇好文章
  7. 【Nodejs】理想论坛帖子爬虫1.02
  8. “/”应用程序中的server错误
  9. mac 下vim 配置文件
  10. 利用vbs设置Java环境变量