问题
What is the difference between setSocketTimout
, setConnectTimout
and setConnectionRequestTimeout
?
RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT)
.setSocketTimeout(500)
.setConnectTimeout(500)
.setConnectionRequestTimeout(500)
.build();
回答1:
Connection timeout
is the timeout until a connection with the server is established.
Socket timeout
is the timeout to receive data.
The method setConnectionRequestTimeout
however is specific for configuring the connection manager. It returns the timeout in milliseconds used when requesting a connection from the connection manager. A timeout value of zero is interpreted as an infinite timeout.
回答2:
ConnectTimeOut:- Refers the maximum time in milliseconds client will wait for connection establishment with server. Within give time the server must have established a connection with Client other it will throw an Exception.
SocketTimeout:- It defines maximum idle/ inactivity time in milliseconds between two consecutive data packets.
refer javadocs for more details
来源:https://stackoverflow.com/questions/39256157/apache-http-setsockettimout-vs-setconnecttimout-vs-setconnectionrequesttimeout