简体   繁体   中英

What is the meaning when a SelectionKey instance call interestOps(0)?

What is the meaning when a SelectionKey instance call interestOps(0) ? 0 is not the enum value defined in SelectionKey . What is the function of interestOps(0) ?

There are four operations: OP_ACCEPT , OP_CONNECT , OP_READ , and OP_WRITE . These aren't enum values, they are integer constants. The values can be bitwise ORed | together if you are interested in multiple operations. For instance:

selectionKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);

interestOps(0) clears the interest set, setting none of the bits.

If those constants were enum Operation values then interestOps(0) would become interestOps(EnumSet.noneOf(Operation.class)) .

What is the meaning when a SelectionKey instance call interestOps(0)?

It means there are no operations of interest in this selection key. Selector.select() will ignore it.

0 is not the enum value defined in SelectionKey.

I don't know what this means. No enum value is defined in SelectionKey .

What is the function of interestOps(0)?

Same question, same answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM