Ejemplo n.º 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;
 }
Ejemplo 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();
    }
  }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }