来自java.net.Socket#setSoTimeout
的javadoc,它说:
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a <B>java.net.SocketTimeoutException</B> is raised, though the Socket is still valid.
对于 http put 操作,客户端可能会上传一个巨大的文件,客户端始终在写入该文件,并且从不从服务器读取数据。
在这种情况下,如果我为 http 客户端设置 SocketTimeout,它会在上传过程中抛出 TimeoutException 吗?
不,
它不会。但是,读取响应代码时可能会引发超时异常。如果对等方在上传过程中关闭连接,它将抛出 IOException"由对等方重置连接"。