FileDocCategorySizeDatePackage
ThreadPool.javaAPI DocExample3705Thu Feb 04 16:10:44 GMT 1999None

ThreadPool

public 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 voidadd(java.lang.Runnable target, java.lang.Object lock)

		try {
			cvFlag.getBusyFlag();
			objects.addElement(new ThreadPoolRequest(target, lock));
			nObjects++;
			cvAvailable.cvSignal();
		} finally {
			cvFlag.freeBusyFlag();
		}
	
public voidaddRequest(java.lang.Runnable target)

		add(target, null);
	
public voidaddRequestAndWait(java.lang.Runnable target)

		Object lock = new Object();
		synchronized(lock) {
			add(target, lock);
			lock.wait();
		}
	
public voidwaitForAll()

		try {
			cvFlag.getBusyFlag();
			while (nObjects != 0)
				cvEmpty.cvWait();
		} finally {
			cvFlag.freeBusyFlag();
		}