From 8f78690c51e195e33611bb74a9cef113aa51d352 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Tue, 22 Jan 2013 12:25:23 +0100 Subject: [PATCH] increase sleep time on idling --- .../intellij/util/io/BaseOutputReader.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/platform/util/src/com/intellij/util/io/BaseOutputReader.java b/platform/util/src/com/intellij/util/io/BaseOutputReader.java index 0fd4d3d02e0d..8f62efa44774 100644 --- a/platform/util/src/com/intellij/util/io/BaseOutputReader.java +++ b/platform/util/src/com/intellij/util/io/BaseOutputReader.java @@ -57,6 +57,13 @@ public abstract class BaseOutputReader { protected void doRun() { try { + final int sleepTimeWhenRead = 1; + final int initialSleepTimeWhenIdle = 5; + final int maxSleepTimeWhenIdle = 200; + final int maxIterationsWithCurrentSleepTime = 50; + int iterationsWithCurrentTime = 0; + int currentSleepTime = initialSleepTimeWhenIdle; + while (true) { boolean read = readAvailable(); @@ -64,7 +71,21 @@ public abstract class BaseOutputReader { break; } - TimeoutUtil.sleep(read ? 1 : 5); // give other threads a chance + // give other threads a chance + if (read) currentSleepTime = sleepTimeWhenRead; + else if (currentSleepTime == sleepTimeWhenRead) { + currentSleepTime = initialSleepTimeWhenIdle; + iterationsWithCurrentTime = 0; + } + else { + ++iterationsWithCurrentTime; + if (iterationsWithCurrentTime == maxIterationsWithCurrentSleepTime) { + iterationsWithCurrentTime = 0; + currentSleepTime = Math.min(2* currentSleepTime, maxSleepTimeWhenIdle); + } + } + + TimeoutUtil.sleep(currentSleepTime); } } catch (IOException e) {