# java.net.SocketTimeoutException: 读取超时

- **ID:** `java/socket-timeout-exception-read-timed-out`
- **领域:** java
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

套接字读取操作在配置的超时时间内未收到数据，通常由网络延迟、服务器过载或防火墙拦截引起。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## 解决方案

1. ```
   Increase the read timeout to a reasonable value (e.g., 30 seconds) using socket.setSoTimeout(30000), and implement a retry mechanism with exponential backoff.
   ```
2. ```
   Check network connectivity with 'ping server-host' and verify server logs for latency or errors; use a connection pool with timeout settings.
   ```

## 无效尝试

- **** — This only delays the failure; if the server is unresponsive, the connection will eventually time out, and it may block threads unnecessarily. (60% 失败率)
- **** — This can cause infinite loops or resource exhaustion if the server never responds, and may overwhelm the network. (75% 失败率)
