FileDocCategorySizeDatePackage
LoopHandler.javaAPI DocExample2425Thu Feb 04 16:10:40 GMT 1999None

LoopHandler

public class LoopHandler extends Object implements Runnable

Fields Summary
protected Thread[]
lookupThreads
protected int
startLoop
protected int
endLoop
protected int
curLoop
protected int
numThreads
Constructors Summary
public LoopHandler(int start, int end, int threads)

		startLoop = curLoop = start;
		endLoop = end;
		numThreads = threads;
		lookupThreads = new Thread[numThreads];
	
Methods Summary
public voidloopDoRange(int start, int end)

	
protected synchronized LoopHandler$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()

		for (int i = 0; i < numThreads; i++) {
			lookupThreads[i] = new Thread(this);
			lookupThreads[i].start();
		}
		for (int i = 0; i < numThreads; i++) {
			try {
				lookupThreads[i].join();
			} catch (InterruptedException iex) {}
		}
	
public voidrun()

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