Methods Summary |
---|
static synchronized void | getThreadPool(int threads)
if (threadpool == null)
threadpool = new ThreadPoolExecutor(
1, 1,
50000L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(),
new PoolHandlerFactory());
if (threads > maxThreads) {
maxThreads = threads;
threadpool.setMaximumPoolSize(maxThreads);
threadpool.setCorePoolSize(maxThreads);
}
|
public void | loopDoRange(int start, int end)
|
protected synchronized javathreads.examples.ch15.PoolLoopHandler$LoopRange | loopGetRange()
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 void | loopProcess()
reset();
FutureTask t[] = new FutureTask[numThreads];
for (int i = 0; i < numThreads; i++) {
t[i] = new FutureTask(this, null);
threadpool.execute(t[i]);
}
for (int i = 0; i < numThreads; i++) {
try {
t[i].get();
} catch (ExecutionException ee) {
} catch (InterruptedException ie) {
}
}
|
public synchronized void | reset()
curLoop = startLoop;
|
public void | run()
LoopRange str;
while ((str = loopGetRange()) != null) {
loopDoRange(str.start, str.end);
}
|
public synchronized void | setRange(int start, int end)
startLoop = start;
endLoop = end;
reset();
|