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. arm指令版本

    arm-linux-readelf 查看 armeabi Tag_CPU_name: "5TE" Tag_CPU_arch: v5TE armeabi-v7a Tag_CPU_na ...

  2. ELK+Filebeat 安装配置入门

    本文地址 http://www.cnblogs.com/jasonxuli/p/6397244.html   https://www.elastic.co 上,elasticsearch,logsta ...

  3. Cocos2dx 3.0 过渡篇(二十七)C++11多线程std::thread的简单使用(下)

    本篇接上篇继续讲:上篇传送门:http://blog.csdn.net/star530/article/details/24186783 简单的东西我都说的几乎相同了,想挖点深的差点把自己给填进去. ...

  4. 我所遭遇过的游戏中间件--FlashOcx

    使用Flash做游戏界面的另一种方式是通过Abode提供flash.ocx处理Flash界面.将Flash图像通过GDI绘制出来后,再将图像数据拷贝到一个D3D的纹理结构中,最后由引擎的D3D接口进行 ...

  5. Copy List with Random Pointer leetcode java

    题目: A linked list is given such that each node contains an additional random pointer which could poi ...

  6. 浅谈jQuery easyui datagrid操作单元格样式

    今天项目上遇到问题,就是表格风格统一的问题,由于用了2个不同的框架,所以如果要大修比较麻烦,考虑到修改表格样式工作量会少很多,所以考虑修改jQuery easyui datagrid数据网格的样式. ...

  7. Java基础(十四):泛型

    一.Java 泛型: Java 泛型(generics)是 JDK 5 中引入的一个新特性, 泛型提供了编译时类型安全检测机制,该机制允许程序员在编译时检测到非法的类型. 泛型的本质是参数化类型,也就 ...

  8. Jenkins——应用篇——插件使用——Publish over SSH

    本文是jenkins应用系统文章的一部分,大部分来自工作和学习中的实践,部分内容来自官方文档和网友的文章,引用的文章会在"參考资料"部分附上原始链接,如无意中侵犯您的权利.请联系Q ...

  9. COM的一些基本概念

      Windows lets you share code at the binary level using DLLs. After all, that's how Windows apps fun ...

  10. Java 调用Web service 加入认证头(soapenv:Header)

    前言 有时候调用web service 会出现 Message does not conform to configured policy [ AuthenticationTokenPolicy(S) ...