Methods Summary |
---|
public int | available()
return idle.size();
|
protected void | configureTask(AbstractRxTask task)
synchronized (task) {
task.setTaskPool(this);
// task.setName(task.getClass().getName() + "[" + inc() + "]");
// task.setDaemon(true);
// task.setPriority(Thread.MAX_PRIORITY);
// task.start();
}
|
public int | getMaxThreads()
return maxTasks;
|
public int | getMinThreads()
return minTasks;
|
public AbstractRxTask | getRxTask()Find an idle worker thread, if any. Could return null.
AbstractRxTask worker = null;
synchronized (mutex) {
while ( worker == null && running ) {
if (idle.size() > 0) {
try {
worker = (AbstractRxTask) idle.remove(0);
} catch (java.util.NoSuchElementException x) {
//this means that there are no available workers
worker = null;
}
} else if ( used.size() < this.maxTasks && creator != null) {
worker = creator.createRxTask();
configureTask(worker);
} else {
try { mutex.wait(); } catch ( java.lang.InterruptedException x ) {Thread.currentThread().interrupted();}
}
}//while
if ( worker != null ) used.add(worker);
}
return (worker);
|
public org.apache.catalina.tribes.transport.RxTaskPool$TaskCreator | getTaskCreator()
return this.creator;
|
private static synchronized int | inc()
return counter++;
|
public void | returnWorker(AbstractRxTask worker)Called by the worker thread to return itself to the
idle pool.
if ( running ) {
synchronized (mutex) {
used.remove(worker);
//if ( idle.size() < minThreads && !idle.contains(worker)) idle.add(worker);
if ( idle.size() < maxTasks && !idle.contains(worker)) idle.add(worker); //let max be the upper limit
else {
worker.setDoRun(false);
synchronized (worker){worker.notify();}
}
mutex.notify();
}
}else {
worker.setDoRun(false);
synchronized (worker){worker.notify();}
}
|
public void | setMaxTasks(int maxThreads)
this.maxTasks = maxThreads;
|
public void | setMinTasks(int minThreads)
this.minTasks = minThreads;
|
public void | stop()
running = false;
synchronized (mutex) {
Iterator i = idle.iterator();
while ( i.hasNext() ) {
AbstractRxTask worker = (AbstractRxTask)i.next();
returnWorker(worker);
i.remove();
}
}
|