2012-03-16 31 views

回答

17

按照documentationhttp.socket.timeout參數控制SO_TIMEOUT值,並且:

如果未設置此參數,讀操作不會超時 (無限超時)。

+0

此設置從4.3.X版本更改。默認是系統超時。 – Chandru 2017-01-09 16:10:57

+0

@Chandru系統超時是什麼意思? – Sam 2017-04-24 21:46:45

+0

@Sam請參閱下面的答案。系統默認超時是爲機器設置的TCP超時(如果有),並因操作系統而異。在mac它是60secs – Chandru 2017-04-27 03:52:16

3

接受的答案不適用於較新版本的HttpClient。 系統通常是60秒。

來自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