java.nio.channels.SelectionKeyNO opts に興味を持たせるにはどうすればよいですか?
SelectionKey#cancel()可能性はありますが、キーが役に立たなくなるのであまり良くありません。
SelectionKeyinterestOps定数があります。OP_ACCEPT、OP_CONNECT、OP_READおよびOP_WRITE、ただし ではありませんOP_NOTHING。それでは、呼び出すのは合法的な操作SelectionKey#interestOpts(**0**)ですか?
ここに例があります。
for(;;) {
selector.select();
for (Iterator<SelectionKey> it = selector.selectedKeys().iterator();
it.hasNext();) {
SelectionKey key = it.next(); it.remove();
key.interestOps(0); // interested in no opts.
// another thread handles socket...
worker.handle();
}
updateKeys(); // if the worker completes handling,
// other interestOpts are set...
}
このコードは今のところうまくいきますが、SelectionKey#interestOpts(0). または、あなたのベストプラクティスを教えていただけますか?