httpclient 有 3個 timeout 可以設定，好像大多的人是設 30 seconds. 這 3個值分別代表什麼意思？
Apache HTTP Client, you can set these timeouts using the request params:
HttpPost request = new HttpPost(url); RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(TIMEOUT_MILLIS) .setConnectTimeout(TIMEOUT_MILLIS) .setConnectionRequestTimeout(TIMEOUT_MILLIS) .build(); request.setConfig(requestConfig);
Returns the timeout in milliseconds used when requesting a connection from the connection manager.
Determines the timeout in milliseconds until a connection is established.
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).
So, the first one, connectionRequestTimeout happens when you have a pool of connections and they are all busy, not allowing the connection manager to give you one connection to make the request.
connectTimeout happens when establishing the connection. For instance while doing the tcp handshake.
socketTimeout like the description says, is the timeout while waiting for data. Usually happens when your server is slow.