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

HttpClient中的Timout的更多相关文章

  1. httpClient中的三种超时设置小结

    httpClient中的三种超时设置小结   本文章给大家介绍一下关于Java中httpClient中的三种超时设置小结,希望此教程能给各位朋友带来帮助. ConnectTimeoutExceptio ...

  2. httpClient 中的post或者get请求

    httpClient相对于java自带的请求功能更加强大,下面就以例子的形式给出: //HttpClient Get请求 private static void register() { try { ...

  3. Java中httpClient中三种超时设置

    本文章给大家介绍一下关于Java中httpClient中的三种超时设置小结 在Apache的HttpClient包中,有三个设置超时的地方: /* 从连接池中取连接的超时时间*/ ConnManage ...

  4. httpclient 中post请求重定向

    背景:使用httpclient 的post请求进行登录,需要重定向登录,请求重定向后的地址 在httpclient中post请求不像get请求自己可以重定向,实现方式是 判断post请求返回码是否是3 ...

  5. 小心 HttpClient 中的 FormUrlEncodeContent 的 bug

    小心 HttpClient 中的 FormUrlEncodeContent 的 bug Intro 最近发现活动室预约项目里的上传图片有时候会有问题,周末找时间测试了一下,发现小图片的上传没问题,大图 ...

  6. HttpClient中post请求http、https示例

    HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 HTTP 协议最新的版本和建 ...

  7. HttpClient中异步方法的同步调用

    在System.Net.Http中,提供了使用Http与远程服务器通讯的httpClient,但是里面都是异步方法,有时候我们并不需要使用异步操作.这个时候可以使用如下的方式来进行同步调用. clas ...

  8. .NET 4.5 HttpClient 中使用Cookie

    为了使用.NET 4.5的HttpClient从WIN2K3换成了WIN7.装VS2010,结果告诉我VS2010不支持.NET 4.5.又装VS2012,接着装.NET FRAMEWORK 4.5. ...

  9. 如何在Apache HttpClient中设置TLS版本

    1.简介 Apache HttpClient是一个底层.轻量级的客户端HTTP库,用于与HTTP服务器进行通信. 在本教程中,我们将学习如何在使用HttpClient时配置支持的传输层安全(TLS)版 ...

随机推荐

  1. TFS WorkItem Permission Setting

    TFS非常强大,但是权限设置确实非常的恶心复杂,这貌似是一切NB又傲慢的软件的通病. 那么,在哪里设置 WorkItem 的权限呢? 第一步: 第二步: 第三步,下面你将一目了然. 第四步,Share ...

  2. Endianess(字节次序)简介

    1. 基础 在解释Endianess前,需要先明白几个基础定义 1) 数据的高位与低位是什么 以1001001为例,则从左边算起是 高位 -> 低位, 简而言之就是左边是高位,右边是低位 而内存 ...

  3. RequireJS 参考文章

    入门: http://www.cnblogs.com/snandy/archive/2012/05/22/2513652.html http://www.cnblogs.com/snandy/arch ...

  4. C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密

    本文源程序下载:http://download.csdn.net/source/2444494 我的项目当中,考虑到安全性,需要为每个客户端分发一个数字证书,同时使用数字证书中的公私钥来进行数据的加解 ...

  5. Android -- 加载大图片的方法

    在android中要加载一张大图片到内存中如果通过如下方式进行: Bitmap bitmap= BitmapFactory.decodeFile("/sdcard/a.jpg"); ...

  6. 应用程序无法正常启动0xc000007b解决

    可能原因: 1.电脑没有安装DirectX9或者DirectX 9.0 组件损坏; 2.电脑没有安装Microsoft Visual C++ 3.电脑上没有安装.net 解决方案: 1/2.下载Dir ...

  7. [Bash] Create Aliases in .bash_profile for Common Bash Commands

    .bash_profile is a file that bash invokes (or more technically sources) before the start of a new ba ...

  8. [Backbone] Customzing Backbone

    Convert the AppointmentForm view below to use Mustache templating. Make sure you remember to change ...

  9. 【Nodejs】理想论坛帖子爬虫1.01

    用Nodejs把Python实现过的理想论坛爬虫又实现了一遍,但是怎么判断所有回调函数都结束没有好办法,目前的spiderCount==spiderFinished判断法在多页情况下还是会提前中止. ...

  10. 免费电子书:The Guide to Minimum Viable Products

    本地下载 来自uxPin的免费电子书