|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javatools.thread.ThreadPool
Implements a pool of threads. Only a limited number of threads can execute at once. If you try to exceed the thread limit you will block waiting. This avoids overloading a machine with threads.
Field Summary | |
(package private) java.util.List |
jobs
|
(package private) java.lang.ThreadGroup |
threadGroup
|
(package private) java.util.List |
threads
|
Constructor Summary | |
ThreadPool(java.lang.String name,
int maxThreads)
|
Method Summary | |
boolean |
anyReadyThreads()
Check whether any pool threads are currently available for use. |
protected void |
finalize()
|
(package private) java.lang.Runnable |
getJob()
Get a job to execute and remove it from the job queue. |
void |
join()
Wait for all threads to complete. |
int |
numberOfActiveThreads()
How many threads are active right now? This number can change at any time, so it is not particularly useful except for providing interesting diagnostics. |
int |
numberOfReadyThreads()
|
void |
queueJob(java.lang.Runnable runnable)
Execute the given procedure when a thread slot becomes available. |
void |
shutdown()
Shutdown all pool threads safely. |
void |
startNow(java.lang.Runnable runnable)
Start a job now. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
java.util.List threads
java.lang.ThreadGroup threadGroup
java.util.List jobs
Constructor Detail |
public ThreadPool(java.lang.String name, int maxThreads)
name
- the name of the ThreadGroupmaxThreads
- the maximum number of threads we allow at once.Method Detail |
java.lang.Runnable getJob()
public void startNow(java.lang.Runnable runnable)
runnable
- public void queueJob(java.lang.Runnable runnable)
runnable
- the runnable that represents the work that shall be done.
public void join()
public int numberOfActiveThreads()
public boolean anyReadyThreads()
public int numberOfReadyThreads()
public void shutdown()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |