/** Returns the number of idle {@link Executor}s that can start working immediately. */ public int countIdle() { int n = 0; for (Executor e : executors) { if (e.isIdle()) n++; } return n; }
private synchronized void setNumExecutors(int n) { if (numExecutors == n) return; // no-op int diff = n - numExecutors; this.numExecutors = n; if (diff < 0) { // send signal to all idle executors to potentially kill them off for (Executor e : executors) if (e.isIdle()) e.interrupt(); } else { // if the number is increased, add new ones addNewExecutorIfNecessary(); } }
/** Returns true if this computer has some idle executors that can take more workload. */ public final boolean isPartiallyIdle() { for (Executor e : executors) if (e.isIdle()) return true; return false; }
/** Returns true if all the executors of this computer are idle. */ @Exported public final boolean isIdle() { if (!oneOffExecutors.isEmpty()) return false; for (Executor e : executors) if (!e.isIdle()) return false; return true; }