Fixed a bug where NioWorker.register() hangs up with high CPU consumption when it failed to open a selector.
This commit is contained in:
parent
7f1ff668f7
commit
00ec5be6dd
@ -86,8 +86,10 @@ class NioWorker implements Runnable {
|
||||
}
|
||||
|
||||
void register(NioSocketChannel channel, ChannelFuture future) {
|
||||
boolean firstChannel = started.compareAndSet(false, true);
|
||||
boolean firstChannel;
|
||||
Selector selector;
|
||||
for (;;) {
|
||||
firstChannel = started.compareAndSet(false, true);
|
||||
if (firstChannel) {
|
||||
boolean success = false;
|
||||
selectorGuard.writeLock().lock();
|
||||
@ -103,13 +105,20 @@ class NioWorker implements Runnable {
|
||||
started.compareAndSet(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
} else {
|
||||
selector = this.selector;
|
||||
if (selector == null) {
|
||||
do {
|
||||
Thread.yield();
|
||||
selector = this.selector;
|
||||
} while (selector == null);
|
||||
} while (selector == null && started.get());
|
||||
}
|
||||
|
||||
if (selector != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user