java NIO SelectionKey.OP_READ 消息为何触发

  • OP_READpublic static final int OP_READOperation-set bit for read operations.

    Suppose that a selection key's interest set contains OP_READ at the start of a selection operation. If the selector detects that the corresponding channel is ready forreading, has reached end-of-stream, has been remotely shut down for further reading, or has an error pending, then it will add OP_READ to the key's ready-operation set and add the key to its selected-key set.

    See Also:
    Constant Field Values

由红色部分可知,OP_READ 事件不仅仅只有可读时才触发,当

channel中数据读完

远程的另一端被关闭

有一个错误的pending

都会触发OP_READ事件!!!

那应该怎么判断channel是否可读呢???



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值