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是否可读呢???



你可能感兴趣的:(Java)