FileDocCategorySizeDatePackage
PoolLoopHandler.javaAPI DocExample2516Thu Feb 04 16:10:42 GMT 1999None

PoolLoopHandler

public class PoolLoopHandler extends Object implements Runnable

Fields Summary
protected ThreadPool
poolThreads
protected int
startLoop
protected int
endLoop
protected int
curLoop
protected int
numThreads
Constructors Summary
public PoolLoopHandler(int start, int end, int threads)

		numThreads = threads;
		poolThreads = new ThreadPool(numThreads);
		setRange(start, end);
	
Methods Summary
public voidloopDoRange(int start, int end)

	
protected synchronized PoolLoopHandler$LoopRangeloopGetRange()

		if (curLoop >= endLoop)
			return null;
		LoopRange ret = new LoopRange();
		ret.start = curLoop;
		curLoop += (endLoop-startLoop)/numThreads+1;
		ret.end = (curLoop<endLoop)?curLoop:endLoop;
		return ret;
	
public voidloopProcess()

		reset();
		for (int i = 0; i < numThreads; i++) {
			poolThreads.addRequest(this);
		}
		try {
				poolThreads.waitForAll();
		} catch (InterruptedException iex) {}
	
public synchronized voidreset()

		curLoop = startLoop;
	
public voidrun()

		LoopRange str;
		while ((str = loopGetRange()) != null) {
			loopDoRange(str.start, str.end);
		}
	
public synchronized voidsetRange(int start, int end)

		startLoop = start;
		endLoop = end;
		reset();