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; } } } }