|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectartofillusion.util.ThreadManager
public class ThreadManager
This class coordinates threads for multi-threaded operations. The execution model provided by this class is a single "task" (e.g. tracing a ray through a single pixel) which must be executed many times. The task is parameterized by a single index (e.g. the column containing the pixel).
To use this class, pass it an object which implements the Task interface. It automatically creates an appropriate number of threads based on the number of available processors. When you call run(), the task is repeatedly executed by the worker threads, with the index running over the desired range. You may invoke run() any number of times (e.g. once for each row of the image). Finally, call finish() to clean up the worker threads.
Nested Class Summary | |
---|---|
static interface |
ThreadManager.Task
This interface defines a task to be performed by the worker threads. |
Constructor Summary | |
---|---|
ThreadManager()
Create a new uninitialized ThreadManager. |
|
ThreadManager(int numIndices,
ThreadManager.Task task)
Create a new ThreadManager. |
Method Summary | |
---|---|
void |
cancel()
Cancel a run which is in progress. |
void |
finish()
Dispose of all the worker threads. |
void |
run()
Perform the task the specified number of times. |
void |
setMaxThreads(int maxThreads)
Set the maximum number of worker threads that should be used for executing the Task. |
void |
setNumIndices(int numIndices)
Set the number of values the index should take on. |
void |
setTask(ThreadManager.Task task)
Set the Task to be executed by the worker threads. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ThreadManager()
public ThreadManager(int numIndices, ThreadManager.Task task)
numIndices
- the number of values the index should take on (from 0 to numIndices-1)task
- the task to performMethod Detail |
---|
public void setNumIndices(int numIndices)
public void setTask(ThreadManager.Task task)
public void setMaxThreads(int maxThreads)
public void run()
public void cancel()
public void finish()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |