chord.util
Class Executor

java.lang.Object
  extended by chord.util.Executor

public final class Executor
extends java.lang.Object

Utility for executing a set of given tasks serially or in parallel.

Author:
Mayur Naik (mhn@cs.stanford.edu)

Constructor Summary
Executor(boolean serial)
          Creates a new serial or parallel executor.
 
Method Summary
 void execute(java.lang.Runnable task)
          Executes given runnable task.
 void waitForCompletion()
          Waits for completion of all submitted tasks and returns afterwards.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Executor

public Executor(boolean serial)
Creates a new serial or parallel executor.

Parameters:
serial - Flag indicating that executor is serial as opposed to parallel.
Method Detail

execute

public void execute(java.lang.Runnable task)
Executes given runnable task. If the executor is serial, this method returns after the submitted task is completed. If the executor is parallel, this method starts a new thread for the submitted task and returns immediately.

Parameters:
task - A task to be executed.
Throws:
java.lang.IllegalArgumentException - if task is null.

waitForCompletion

public void waitForCompletion()
                       throws java.lang.InterruptedException
Waits for completion of all submitted tasks and returns afterwards.

Throws:
java.lang.InterruptedException - if any occurs during waiting for tasks to be completed.