Fixed a bug where NioWorker.register() hangs up with high CPU consumption when it failed to open a selector.

This commit is contained in:
Trustin Lee 2008-11-06 11:19:48 +00:00
parent 486218ab28
commit 7f1ff668f7

View File

@ -89,14 +89,19 @@ class NioWorker implements Runnable {
boolean firstChannel = started.compareAndSet(false, true);
Selector selector;
if (firstChannel) {
boolean success = false;
selectorGuard.writeLock().lock();
try {
this.selector = selector = Selector.open();
success = true;
} catch (IOException e) {
throw new ChannelException(
"Failed to create a selector.", e);
} finally {
selectorGuard.writeLock().unlock();
if (!success) {
started.compareAndSet(true, false);
}
}
} else {
selector = this.selector;