這個SocketException拋出ObjectInputStream.readObject()方法,是什麼原因導致這個excetpion?此外,客戶端和服務器套接字的soTimeout值均爲0,並且KeepAlive值爲false。什麼原因導致:java.net.SocketException:連接超時,不是SocketTimeoutException
{2012-01-09 17:44:13,908} ERROR java.net.SocketException: Connection timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:146)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:312)
at sun.security.ssl.InputRecord.read(InputRecord.java:350)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:809)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:766)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:94)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:69)
at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2265)
at java.io.ObjectInputStream$BlockDataInputStream.peek(ObjectInputStream.java:2558)
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2568)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1314)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
大約從setSoTimeout方法的Java API文件,如果該方法被設置無零值,則次期滿時,僅SocketTimeoutException被拋出,而不是SocketException:連接超時,於是,這異常不應該與setSotimeoutMethod相關。
public void setSoTimeout(int timeout) throws SocketException
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
java.net.SocketTimeoutException is raised, though the Socket is still valid. The
option must be enabled prior to entering the blocking operation to have effect. The
timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.
然而,PlainSocketImpl返回的值(在這裏,是SSLSocketImpl).getTimeout()由setSoTimeout()方法轉移,那麼它仍然是一個非常奇怪的方法。
SocketInputStream.socketRead0(FileDescriptor fd, byte b[], int off, int len, int timeout)
the timeout value is passed in the constructor of SocketInputStream:SocketInputStream(PlainSocketImpl impl) throws IOException {}
timeout = impl.getTimeout();