|
Dresden OCL Toolkit | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ThreadGroup
tudresden.ocl.injection.reverseeng.ThreadPool
A pool of indistinguishable worker threads that can perform tasks.
A ThreadPool consists of a number of identical worker threads and a bag of tasks. Whenever a thread finishes one task it grabs the next available task out of the bag and performs it. The ThreadPool allows to add tasks to be performed, and to control the number of threads in the group.
Nested Class Summary | |
private static class |
ThreadPool.PooledThread
|
Field Summary | |
private int |
m_cThreads
The number of worker threads in this pool. |
private int |
m_cThreadsToAdd
The number of threads that need to be added (or removed if negative!). |
private List |
m_lrTasks
The bag of tasks implemented as a list. |
private int |
m_nNextID
The next worker thread ID. |
private Object |
m_oTasksLock
Monitor synchronizing access to the bag of tasks. |
private Object |
m_oThreadCountLock
Monitor synchronizing access to the thread count variables. |
Fields inherited from class java.lang.ThreadGroup |
|
Constructor Summary | |
ThreadPool()
Creates new ThreadPool with a default name and a default number of threads in the current thread group. |
|
ThreadPool(String sName)
Creates new ThreadPool with a default number of threads in the current thread group. |
|
ThreadPool(String sName,
int cInitialThreads)
Creates new ThreadPool in the current thread group. |
|
ThreadPool(String sName,
int cInitialThreads,
ThreadGroup tg)
Creates new ThreadPool in the specified thread group. |
Method Summary | |
void |
addTask(Runnable rTask)
Add a task to the bag of tasks needing to be performed. |
void |
addThreads(int cThreadsToAdd)
Add the specified number of threads to the pool of worker threads. |
private void |
checkForDeath()
Throws a ThreadDeath if there are still threads that need to die. |
private Runnable |
dequeueTask()
Used internally by PooledThread to dequeue the next task. |
private Object |
getTasksLock()
|
private Object |
getThreadCountLock()
|
void |
removeThreads(int cThreadsToRemove)
Mark the specified number of threads as needing to be removed. |
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 transient Object m_oThreadCountLock
private int m_cThreads
private int m_cThreadsToAdd
addThreads(int)
,
removeThreads(int)
private int m_nNextID
private transient Object m_oTasksLock
private List m_lrTasks
Constructor Detail |
public ThreadPool()
public ThreadPool(String sName)
public ThreadPool(String sName, int cInitialThreads)
sName
- the name of the ThreadPool.cInitialThreads
- the initial number of worker threads.public ThreadPool(String sName, int cInitialThreads, ThreadGroup tg)
sName
- the name of the ThreadPool.cInitialThreads
- the initial number of worker threads.tg
- the ThreadGroup in which the pool is to be created.Method Detail |
private Object getThreadCountLock()
private Object getTasksLock()
private Runnable dequeueTask()
This can return in two cases:
public void addTask(Runnable rTask)
rTask
- the task to be added.public void addThreads(int cThreadsToAdd)
cThreadsToAdd
- the number of threads to be added.public void removeThreads(int cThreadsToRemove)
Note that the threads will be killed only after they completed the current task.
private void checkForDeath()
|
Dresden OCL Toolkit | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |