2014-01-15 54 views
0

java.net.Socket#setSoTimeout的Javadoc,它說:如何理解http放置的SocketTimeout?

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嗎?

回答

0

不,它不會。但是,讀取響應代碼時可能會引發超時異常。如果對端在上傳過程中關閉連接,則會拋出一個IOException'通過對等方重置連接'。