|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.ThreadGroup
com.brackeen.javagamebook.util.ThreadPool
public class ThreadPool
A thread pool is a group of a limited number of threads that are used to execute tasks.
| Nested Class Summary | |
|---|---|
private class |
ThreadPool.PooledThread
A PooledThread is a Thread in a ThreadPool group, designed to run tasks (Runnables). |
| Field Summary | |
|---|---|
private boolean |
isAlive
|
private java.util.LinkedList |
taskQueue
|
private int |
threadID
|
private static int |
threadPoolID
|
| Constructor Summary | |
|---|---|
ThreadPool(int numThreads)
Creates a new ThreadPool. |
|
| Method Summary | |
|---|---|
void |
close()
Closes this ThreadPool and returns immediately. |
protected java.lang.Runnable |
getTask()
|
void |
join()
Closes this ThreadPool and waits for all running threads to finish. |
void |
runTask(java.lang.Runnable task)
Requests a new task to run. |
protected void |
threadStarted()
Signals that a PooledThread has started. |
protected void |
threadStopped()
Signals that a PooledThread has stopped. |
| Methods inherited from class java.lang.ThreadGroup |
|---|
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtException |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private boolean isAlive
private java.util.LinkedList taskQueue
private int threadID
private static int threadPoolID
| Constructor Detail |
|---|
public ThreadPool(int numThreads)
numThreads - The number of threads in the pool.| Method Detail |
|---|
public void runTask(java.lang.Runnable task)
Tasks start execution in the order they are received.
task - The task to run. If null, no action is taken.
java.lang.IllegalStateException - if this ThreadPool is
already closed.
protected java.lang.Runnable getTask()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void close()
public void join()
protected void threadStarted()
protected void threadStopped()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||