private void selectLoop() throws IOException { while (!stop) { processTaskQueue(); int selectedKeys = selector.select(SELECT_WAIT_TIME_MILLIS); if (selectedKeys > 0) { processSelectionKeys(); } } }
private void selectLoop() throws IOException { while (!stop) { processTaskQueue(); int selectedKeys = selector.select(SELECT_WAIT_TIME_MILLIS); if (selectedKeys > 0) { processSelectionKeys(); } } }
private void selectNowLoop() throws IOException { long idleRound = 0; while (!stop) { boolean tasksProcessed = processTaskQueue(); int selectedKeys = selector.selectNow(); if (selectedKeys > 0) { processSelectionKeys(); idleRound = 0; } else if (tasksProcessed) { idleRound = 0; } else if (idleStrategy != null) { idleRound++; idleStrategy.idle(idleRound); } } }
private void selectNowLoop() throws IOException { long idleRound = 0; while (!stop) { boolean tasksProcessed = processTaskQueue(); int selectedKeys = selector.selectNow(); if (selectedKeys > 0) { processSelectionKeys(); idleRound = 0; } else if (tasksProcessed) { idleRound = 0; } else if (idleStrategy != null) { idleRound++; idleStrategy.idle(idleRound); } } }
private void selectLoopWithFix() throws IOException { int idleCount = 0; while (!stop) { processTaskQueue(); long before = currentTimeMillis(); int selectedKeys = selector.select(SELECT_WAIT_TIME_MILLIS); if (selectedKeys > 0) { idleCount = 0; processSelectionKeys(); } else if (!taskQueue.isEmpty()) { idleCount = 0; } else { // no keys were selected, not interrupted by wakeup therefore we hit an issue with JDK/network stack long selectTimeTaken = currentTimeMillis() - before; idleCount = selectTimeTaken < SELECT_WAIT_TIME_MILLIS ? idleCount + 1 : 0; if (selectorBugDetected(idleCount)) { rebuildSelector(); idleCount = 0; } } } }
private void selectLoopWithFix() throws IOException { int idleCount = 0; while (!stop) { processTaskQueue(); long before = currentTimeMillis(); int selectedKeys = selector.select(SELECT_WAIT_TIME_MILLIS); if (selectedKeys > 0) { idleCount = 0; processSelectionKeys(); } else if (!taskQueue.isEmpty()) { idleCount = 0; } else { // no keys were selected, not interrupted by wakeup therefore we hit an issue with JDK/network stack long selectTimeTaken = currentTimeMillis() - before; idleCount = selectTimeTaken < SELECT_WAIT_TIME_MILLIS ? idleCount + 1 : 0; if (selectorBugDetected(idleCount)) { rebuildSelector(); idleCount = 0; } } } }