|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.sys.TaskObject
ewe.sys.ThreadPool
A ThreadPool represents a pool of running Threads that are waiting for tasks to run. You call addTask() to add a Task Object to the pool and an idle Thread is assigned to run the task. If no idle Thread is available a new one is created and used. ThreadPools can greatly improve performance in server applications since it reduces the overhead of creating new Threads. This has a greater effect under a true Java VM since Ewe Threads are very lightweight and really don't take any more system resources than any other object.
You can specify a minimum number of idle Threads and Threads are added to the pool to make up to that minimum.
You can specify a maximum number of Threads and if the maximum is reached all new tasks will have to wait until older ones are finished and their Threads are freed. If all Threads are idle and there are more idle threads than the specified minimum, the Threads will eventually terminate and be discarded until only the minimum number of Threads remain.
| Field Summary | |
int |
maxThreads
The maximum number of allowed threads. |
int |
minThreads
The minimum number of allowed threads. |
int |
waitTime
How long (in seconds) before an idle thread decides to exit (if there are no tasks to run and if the number of threads is already greater than the minimum). |
| Fields inherited from class ewe.sys.TaskObject |
handle, interruptThreadToStop, myThread, napIterations, napTime, shouldStop |
| Constructor Summary | |
ThreadPool()
Create a ThreadPool with a minimum of 10 threads and no maximum. |
|
ThreadPool(int min,
int max)
Create a ThreadPool specifying the minimum and maximum number of threads. |
|
| Method Summary | |
void |
addTask(Runnable toRun)
Use this to add a task to run. |
void |
addTask(Runnable toRun,
int timeOutInSeconds)
Use this to add a task to run. |
void |
close()
After calling this no more tasks can be added and any spare threads will eventually die. |
protected void |
doRun()
Override this method if you want to use an mThread to run your Task. |
void |
makeUpToMinimum()
Add threads until the minimum has been achieved. |
| Methods inherited from class ewe.sys.TaskObject |
checkAbortFail, checkFailure, doStart, doStop, exec, getHandle, nap, run, setNapTime, show, sleep, start, startTask, stopTask, waitOn, waitOnAny, waitOnSuccess, yield, yield |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
public int minThreads
public int maxThreads
public int waitTime
| Constructor Detail |
public ThreadPool()
public ThreadPool(int min,
int max)
| Method Detail |
public void makeUpToMinimum()
protected void doRun()
TaskObject
doRun in class TaskObject
public void addTask(Runnable toRun,
int timeOutInSeconds)
throws IllegalStateException
toRun - The task to run.timeOutInSeconds - A maximum length of time for the task to run for. If this is
zero or less then the task will have no maximum time.
IllegalStateException - if the ThreadPool is closed.
public void addTask(Runnable toRun)
throws IllegalStateException
toRun - The task to run.
IllegalStateException - if the ThreadPool is closed.public void close()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||