私はJavaのノンブロッキングIOに不慣れです。質問があります-チャネルからの読み取りが完了した後、セレクターからこのチャネルの選択キーを削除する前にサーバーからの新しいパケットが到着した場合、非ブロッキングチャネルの準備はセレクターによって失われますか?ここにサンプルコード:
Selector selector;
// ......
while (true) {
selector.select();
Set<SelectionKey> set = selector.selectedKeys();
Iterator<SelectionKey> iterator = set.iterator();
while (iterator.hasNext()) {
SelectionKey key = iterator.next();
SocketChannel channel = (SocketChannel) key.channel();
ByteBuffer byteBuffer = ByteBuffer.allocate(GOOD_ENOUGH_CAPACITY);
while (channel.read(byteBuffer) > 0) ;
// HERE ! What happen if server started to write new message here?
// Will this channel be selected on next selector.select() ?
iterator.remove();
}
}