RFR: 8287580: (se) CancelledKeyException during channel registration [v3]
Alan Bateman
alanb at openjdk.java.net
Fri Jun 3 07:22:25 UTC 2022
On Thu, 2 Jun 2022 22:14:27 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> Ignore `CancelledKeyException` during registration.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>
> 8287580: Revert change to AbstractSelectableChannel; reduce iterations in test
Here's a suggestion for a test that is closer to what I suggested in one of the early messages. The main difference is that there is a loop calling selectNow so that the cancelled key is flushed and subsequent calls to register work as a new registration.
import java.nio.channels.*;
public class CancelDuringRegister {
private static volatile boolean done;
public static void main(String[] args) throws Exception {
try (Selector sel = Selector.open()) {
// create thread to cancel all keys in the selector's key set
var thread = new Thread(() -> {
while (!done) {
sel.keys().forEach(SelectionKey::cancel);
}
});
thread.start();
try (SocketChannel sc = SocketChannel.open()) {
sc.configureBlocking(false);
for (int i = 0; i <100_000; i++) {
sc.register(sel, SelectionKey.OP_READ);
sel.selectNow();
}
} finally {
done = true;
thread.join();
}
}
}
}
-------------
PR: https://git.openjdk.java.net/jdk/pull/8978
More information about the nio-dev
mailing list