ThreadPoolpublic class ThreadPool extends Object
Fields Summary |
---|
Vector | objects | int | nObjects | CondVar | cvAvailable | CondVar | cvEmpty | BusyFlag | cvFlag |
Constructors Summary |
---|
public ThreadPool(int n)
cvFlag = new BusyFlag();
cvAvailable = new CondVar(cvFlag);
cvEmpty = new CondVar(cvFlag);
objects = new Vector();
for (int i = 0; i < n; i++)
new ThreadPoolThread(this, i).start();
|
Methods Summary |
---|
private void | add(java.lang.Runnable target, java.lang.Object lock)
try {
cvFlag.getBusyFlag();
objects.addElement(new ThreadPoolRequest(target, lock));
nObjects++;
cvAvailable.cvSignal();
} finally {
cvFlag.freeBusyFlag();
}
| public void | addRequest(java.lang.Runnable target)
add(target, null);
| public void | addRequestAndWait(java.lang.Runnable target)
Object lock = new Object();
synchronized(lock) {
add(target, lock);
lock.wait();
}
| public void | waitForAll()
try {
cvFlag.getBusyFlag();
while (nObjects != 0)
cvEmpty.cvWait();
} finally {
cvFlag.freeBusyFlag();
}
|
|