visad.util
Class ThreadManager

java.lang.Object
  extended by visad.util.ThreadManager

public class ThreadManager
extends Object

This class provides support for running a collection of Runnables concurrently. It will collect and then throw any exceptions that are thrown. It uses the static maxThreads as the number of threads to run. The default is 1, resulting in sequential execution.


Nested Class Summary
static interface ThreadManager.MyRunnable
          MyRunnable
 
Field Summary
 boolean debug
           
static int MAX_THREADS
           
 
Constructor Summary
ThreadManager()
           
ThreadManager(int maxThreads)
           
ThreadManager(String theName)
          Constructor with name specified
 
Method Summary
 void addRunnable(ThreadManager.MyRunnable runnable)
           
static void clearTimes()
           
 void debug(String msg)
           
static void doWork(int amt, int[] A)
           
 List<Exception> getExceptions()
          Return the list of any exceptions that were thrown when running the threads
 int getNumRunnables()
           
 void handleException(Exception exc)
           
static void main(String[] args)
          Main method for testing
 void runAllParallel()
           
 void runInParallel()
           
 void runInParallel(boolean doAverage)
           
 void runInParallel(int maxThreads)
           
 void runnableStarted()
           
 void runnableStopped()
           
 void runSequentially()
           
static void setGlobalMaxThreads(int max)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public boolean debug

MAX_THREADS

public static final int MAX_THREADS
See Also:
Constant Field Values
Constructor Detail

ThreadManager

public ThreadManager()

ThreadManager

public ThreadManager(String theName)
Constructor with name specified

Parameters:
theName -

ThreadManager

public ThreadManager(int maxThreads)
Parameters:
maxThreads -
Method Detail

setGlobalMaxThreads

public static void setGlobalMaxThreads(int max)
Parameters:
max -

debug

public void debug(String msg)

clearTimes

public static void clearTimes()

addRunnable

public void addRunnable(ThreadManager.MyRunnable runnable)
Parameters:
runnable -

handleException

public void handleException(Exception exc)
Parameters:
exc -

runnableStopped

public void runnableStopped()

runnableStarted

public void runnableStarted()

getNumRunnables

public int getNumRunnables()
Returns:
count of Runnables

runInParallel

public void runInParallel(int maxThreads)
                   throws VisADException,
                          RemoteException
Parameters:
maxThreads -
Throws:
RemoteException
VisADException

runSequentially

public void runSequentially()
                     throws VisADException,
                            RemoteException
Throws:
RemoteException
VisADException

runAllParallel

public void runAllParallel()
                    throws VisADException,
                           RemoteException
Throws:
RemoteException
VisADException

runInParallel

public void runInParallel()
                   throws VisADException,
                          RemoteException
Throws:
RemoteException
VisADException

runInParallel

public void runInParallel(boolean doAverage)
                   throws VisADException,
                          RemoteException
Parameters:
doAverage -
Throws:
RemoteException
VisADException

getExceptions

public List<Exception> getExceptions()
Return the list of any exceptions that were thrown when running the threads

Returns:
The exceptions that were thrown

doWork

public static final void doWork(int amt,
                                int[] A)

main

public static void main(String[] args)
                 throws Exception
Main method for testing

Parameters:
args - args
Throws:
Exception