0
我正在使用NIO中的Java选择器。我正在使用特定的频道和选择器注册我的选择键/兴趣键。现在,我的要求是为特定的选择器设置两个或多个兴趣集。注册多个SelectionKey
我所做的就是做两个selectionkeys有不同的选择选项如下:
try {
Selector selector = Selector.open();
ServerSocketChannel channel = ServerSocketChannel.open();
//FileChannel channel = new FileInputStream("").getChannel();
channel.configureBlocking(false);
SelectionKey key1 = channel.register(selector, SelectionKey.OP_READ);
SelectionKey key2 = channel.register(selector, SelectionKey.OP_WRITE);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我的问题是,有没有什么办法可以避开做两个不同势钥匙?
更常见的名称是“按位或” https://en.wikipedia.org/wiki/Bitwise_operation#OR –