예제 #1
0
 /** 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;
 }
예제 #2
0
  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();
    }
  }
예제 #3
0
 /** 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;
 }
예제 #4
0
 /** 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;
 }