Java HttpComponent 客户端的默认超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9734384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Default timeout for HttpComponent Client
提问by thinkanotherone
I can't find any documentation on the default httpParams for httpclient 4.1 ?
我找不到有关 httpclient 4.1 的默认 httpParams 的任何文档?
What's the default socket timeout when I do a GET ?
当我执行 GET 时,默认的套接字超时是多少?
采纳答案by beny23
According to the documentation, the http.socket.timeout
parameter controls the SO_TIMEOUT value, and:
根据文档,该http.socket.timeout
参数控制 SO_TIMEOUT 值,并且:
If this parameter is not set, read operations will not time out (infinite timeout).
如果未设置此参数,则读取操作不会超时(无限超时)。
回答by Chandru
The accepted answer is not applicable for newer versions of HttpClient. Versions 4.3.X and above use the system default which is usually 60 secs.
接受的答案不适用于较新版本的 HttpClient。4.3.X 及以上版本使用系统默认值,通常为 60 秒。
Taken from HttpClient javadoc.
取自 HttpClient javadoc。
public int getSocketTimeout()
Defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets).
A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).
Default: -1
回答by yqbjtu
A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).
超时值为零被解释为无限超时。负值被解释为未定义(系统默认值)。
Default: -1
默认值:-1
回答by Mike Murphy
For Apache HttpClient version 4.x upwards
对于 Apache HttpClient 4.x 以上版本
int timeout = 5*60; // seconds (5 minutes)
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout * 1000)
.setConnectionRequestTimeout(timeout * 1000)
.setSocketTimeout(timeout * 1000).build();
HttpClient httpClient =
HttpClientBuilder.create().setDefaultRequestConfig(config).build();