Home›Java›java.net.SocketTimeoutException: Read timed out vs connect timed out (Java Fix)
Intermediate
3 min · November 15, 2026
java.net.SocketTimeoutException: Read timed out vs connect timed out (Java Fix)
'Read timed out' means you connected but the reply took longer than your read timeout; 'connect timed out' means nothing answered the connection at all.
N
NarenFounder & Principal Engineer
20+ years shipping production Java in banking & fintech. Drawn from code that ran under real load.
Retry only idempotent requests; make slow work async.
✦ Definition~90s read
What is java.net.SocketTimeoutException?
java.net.SocketTimeoutException is thrown when a socket operation waits longer than its timeout. 'connect timed out' means the TCP connection was never established within the connect timeout. 'Read timed out' means the connection was established, but no data arrived within the read (SO_TIMEOUT) timeout.
★
Connect timed out: you rang and nobody picked up.
Plain-English First
Connect timed out: you rang and nobody picked up. Read timed out: they picked up, you asked a question, and you hung up before they finished answering.
At month end every report request failed after exactly 5 seconds with Read timed out, while the server logged 200 OK in 8 seconds. The client simply stopped waiting.
Two Timeouts, Two Meanings
The message tells you which phase timed out. Connect covers the TCP handshake; read covers waiting for data after the request is sent.
messages.txtTEXT
1
2
java.net.SocketTimeoutException: connect timed out -> never connected
java.net.SocketTimeoutException: Read timed out -> connected, reply too slow
🎯 Key Takeaway
Read the message carefully.
Set Both Explicitly (HttpURLConnection)
The defaults are 0, which means wait forever. One slow server can tie up every thread.
Client.javaJAVA
1
2
3
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(3_000); // fail fast if unreachable
conn.setReadTimeout(15_000); // fits this endpoint
🎯 Key Takeaway
0 = infinite.
java.net.http.HttpClient
The newer client separates the two too, but throws HttpConnectTimeoutException and HttpTimeoutException.