如何理解SocketTimeout for http put?

时间:2014-01-15 12:10:33

标签: java sockets http timeout

来自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吗?

1 个答案:

答案 0 :(得分:0)

不,不会。但是,在读取响应代码时可能会抛出超时异常。如果对等体在上载期间关闭连接,它将抛出IOException'连接由对等体重置'。