NioEventLoop ensures that all submitted tasks are executed immediately.

Motivation:
If a task was submitted when wakenUp value was true, the task didn't get a chance to call Selector#wakeup.
So we need to check task queue again before executing select operation. If we don't, the task might be pended until select operation was timed out.
It might be pended until idle timeout if IdleStateHandler existed in pipeline.

Modifications:
Execute Selector#select in a non-blocking manner if there's a task submitted when wakenUp value was true.

Result:
Every tasks in NioEventLoop will not be pended.
This commit is contained in:
Hyangtack Lee 2016-05-16 12:01:19 +09:00 committed by Norman Maurer
parent 877767da00
commit f44f3e7926

View File

@ -652,6 +652,16 @@ public final class NioEventLoop extends SingleThreadEventLoop {
break; break;
} }
// If a task was submitted when wakenUp value was true, the task didn't get a chance to call
// Selector#wakeup. So we need to check task queue again before executing select operation.
// If we don't, the task might be pended until select operation was timed out.
// It might be pended until idle timeout if IdleStateHandler existed in pipeline.
if (hasTasks() && wakenUp.compareAndSet(false, true)) {
selector.selectNow();
selectCnt = 1;
break;
}
int selectedKeys = selector.select(timeoutMillis); int selectedKeys = selector.select(timeoutMillis);
selectCnt ++; selectCnt ++;