Почему я получаю CancelledKeyException
несколько раз в день? Должен ли я что-то сделать? Неправильно ли мой код?
Iterator<SelectionKey> keys = selector.selectedKeys().iterator();
while (keys.hasNext()) {
SelectionKey key = (SelectionKey) keys.next();
keys.remove();
try {
if (key.isValid()) {
if (key.isReadable()) {
readHandler.handle((Connection) key.attachment());
}
if (key.isWritable()) {
writeHandler.handle((Connection) key.attachment());
}
if (key.isAcceptable()) {
acceptHandler.handle(key);
}
}
} catch (CancelledKeyException e) {
_logger.error("CanceledKeyException in while loop:", e);
}
}
Исключение:
java.nio.channels.CancelledKeyException: null
at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55) ~[na:1.6.0_12]
at sun.nio.ch.SelectionKeyImpl.readyOps(SelectionKeyImpl.java:69) ~[na:1.6.0_12]
at java.nio.channels.SelectionKey.isWritable(SelectionKey.java:294) ~[na:1.6.0_12]
at project.engine.io.SimpleReactor.work(SimpleReactor.java:194) ~[engine-02.06.11.jar:na]
at project.server.work.AbstractWorker$1.run(AbstractWorker.java:20) [server-21.05.11.jar:na]
at java.lang.Thread.run(Thread.java:619) [na:1.6.0_12]