Deregister a key immediately?

Wang Weijun at
Fri Jun 13 09:07:44 UTC 2014


I am using NIO Selector to monitor several channels. Whenever an exception is thrown on one channel I call key.cancel(). At the beginning of the loop I also call selector.keys.isEmpty() to see if there are channels still working. However, it seems key.cancel() does not automatically remove it from selector.keys() so I add a dummy after the cancel call. Until now I didn't find it harmful but is there another way to deregister the key without calling select()?

Or, I should not rely on selector.keys.isEmpty()?


More information about the nio-dev mailing list