When using Apache's HttpClient, I can set the following three timeout values (milliseconds), but I didn't understand the difference well, so I tried to summarize them myself.
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(30000)
.setConnectionRequestTimeout(30000)
.setSocketTimeout(30000)
.build();
HttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(config)
.build();
ConnetionTimeout The timeout value for sending a connection request to the server and receiving a response that the connection has been established. In short, set the time allowed for a connection to be established with a 3-way handshake.
ConnectionRequestTimeout The timeout value after the above connection is completed until the request is sent to the server and the response is returned.
SocketTimeut A timeout value used to monitor socket communication. Packets are continuously received in socket communication, but if the reception interval is longer than this value, a timeout (= SocketTimeoutException) occurs.
Recommended Posts