A workaround for 100% CPU consumption issue in NIO selectors, suggested by David M. Lloyd

This commit is contained in:
Trustin Lee 2009-10-27 03:27:32 +00:00
parent d0890c1af0
commit 72a35e3e24
2 changed files with 4 additions and 10 deletions

View File

@ -216,7 +216,7 @@ class NioDatagramWorker implements Runnable {
}
try {
int selectedKeyCount = selector.select(500);
selector.select(500);
// 'wakenUp.compareAndSet(false, true)' is always evaluated
// before calling 'selector.wakeup()' to reduce the wake-up
@ -252,10 +252,7 @@ class NioDatagramWorker implements Runnable {
processRegisterTaskQueue();
processWriteTaskQueue();
if (selectedKeyCount > 0) {
processSelectedKeys(selector.selectedKeys());
}
processSelectedKeys(selector.selectedKeys());
// Exit the loop when there's nothing to handle (the registered
// key set is empty.

View File

@ -155,7 +155,7 @@ class NioWorker implements Runnable {
}
try {
int selectedKeyCount = selector.select(500);
selector.select(500);
// 'wakenUp.compareAndSet(false, true)' is always evaluated
// before calling 'selector.wakeup()' to reduce the wake-up
@ -191,10 +191,7 @@ class NioWorker implements Runnable {
processRegisterTaskQueue();
processWriteTaskQueue();
if (selectedKeyCount > 0) {
processSelectedKeys(selector.selectedKeys());
}
processSelectedKeys(selector.selectedKeys());
// Exit the loop when there's nothing to handle.
// The shutdown flag is used to delay the shutdown of this