java nio 连接超时,“ java.io.IOException:连接超时”与“和“ SocketTimeoutException:读取超时”;...

If I set a socket SoTimeout, and read from it. when read time exceed the timeout limit, I'll get an "SocketTimeoutException: Read timed out".

and here is the stack in my case:

java.net.SocketTimeoutException: Read timed out

at java.net.SocketInputStream.socketRead0(Native Method)

at java.net.SocketInputStream.read(SocketInputStream.java:150)

at java.net.SocketInputStream.read(SocketInputStream.java:121)

at java.io.FilterInputStream.read(FilterInputStream.java:133)

at org.apache.hadoop.ipc.Client$Connection$PingInputStream.read(Client.java:277)

at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)

at java.io.BufferedInputStream.read(BufferedInputStream.java:254)

at java.io.DataInputStream.readInt(DataInputStream.java:387)

at org.apache.hadoop.ipc.Client$Connection.receiveResponse(Client.java:527)

at org.apache.hadoop.ipc.Client$Connection.run(Client.java:462)

but here I encountered "IOExcetion: Connection timed out", i don't know how it happened.

Stacks:

java.io.IOException: Connection timed out

at sun.nio.ch.FileDispatcher.read0(Native Method)

at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:21)

at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:198)

at sun.nio.ch.IOUtil.read(IOUtil.java:171)

at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:245)

at org.apache.hadoop.net.SocketInputStream$Reader.performIO(SocketInputStream.java:55)

at org.apache.hadoop.net.SocketIOWithTimeout.doIO(SocketIOWithTimeout.java:142)

at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:155)

at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:128)

at java.io.FilterInputStream.read(FilterInputStream.java:116)

at org.apache.hadoop.ipc.Client$Connection$PingInputStream.read(Client.java:277)

at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)

at java.io.BufferedInputStream.read(BufferedInputStream.java:237)

at java.io.DataInputStream.readInt(DataInputStream.java:370)

at org.apache.hadoop.ipc.Client$Connection.receiveResponse(Client.java:527)

at org.apache.hadoop.ipc.Client$Connection.run(Client.java:462)

Can someone tell me what's the differences between the two exceptions, Thanks.

解决方案

A connection timeout means you attempted to connect to the remote IP/port pair and failed to do so: it did not answer at all. Another possible error at that stage would be connection refused, in which this pair is available but rejected your connection attempt. Both of these errors appear on the initial setup of a socket. Note that these errors only occur with TCP, since a TCP connection requires the establishment of a session.

When you have a socket read timeout, it means you are connected, but failed to read data in time. Timeouts on sockets are configurable. You may also get a connection reset error, which means you did connect successfully, but the other end decided that after all you're not worth it :p

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值