Deregister a key immediately?

Wang Weijun weijun.wang at oracle.com
Fri Jun 13 09:07:44 UTC 2014


Hi

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 selector.select(1) 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()?

Thanks
Max



More information about the nio-dev mailing list