I have request config set like below:
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000)
.setSocketTimeout(10000)
.setConnectionRequestTimeout(5000).build();
Then using this config to submit a file to a server which will take up to a min to respond the file submission status. Executing this will throw java.net.SocketTimeoutException: Read timed out
After some experiments, I found out that:
When I set either connetTimeout or socketTimeout, the SocketTimeoutException will be thrown after the timeout I set for connectTimeout or socketTimeout.
When I set both connectTimeout and sockettimeout, the SocketTimeoutException will be thrown after the timeout I set for socketTimeout but not connectTimeout.
Can someone explain this? I didn't expect setting the connetTimeout will throw the socketTimeout after the connectTimeout, because the client and server establish the connection in time. The server just takes time to process the request before responding.