Methods Summary |
---|
public void | addWorker(java.lang.Runnable worker)Adds a new worker to the pool
if (log.isDebugEnabled()) {
log.debug("Enter: ThreadPool::addWorker");
}
if (_shutdown || threadcount == maxPoolSize) {
throw new IllegalStateException(Messages.getMessage("illegalStateException00"));
}
Thread thread = new Thread(worker);
threads.put(worker, thread);
threadcount++;
thread.start();
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::addWorker");
}
|
public synchronized void | awaitShutdown()Await shutdown of the worker
if (log.isDebugEnabled()) {
log.debug("Enter: ThreadPool::awaitShutdown");
}
if (!_shutdown)
throw new IllegalStateException(Messages.getMessage("illegalStateException00"));
while (threadcount > 0)
wait();
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::awaitShutdown");
}
|
public synchronized boolean | awaitShutdown(long timeout)Await shutdown of the worker
if (log.isDebugEnabled()) {
log.debug("Enter: ThreadPool::awaitShutdown");
}
if (!_shutdown)
throw new IllegalStateException(Messages.getMessage("illegalStateException00"));
if (threadcount == 0) {
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::awaitShutdown");
}
return true;
}
long waittime = timeout;
if (waittime <= 0) {
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::awaitShutdown");
}
return false;
}
for (; ;) {
wait(waittime);
if (threadcount == 0) {
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::awaitShutdown");
}
return true;
}
waittime = timeout - System.currentTimeMillis();
if (waittime <= 0) {
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::awaitShutdown");
}
return false;
}
}
|
public void | cleanup()
if (log.isDebugEnabled()) {
log.debug("Enter: ThreadPool::cleanup");
}
if (!isShutdown()) {
safeShutdown();
awaitShutdown();
}
synchronized(this) {
threads.clear();
_shutdown = false;
}
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::cleanup");
}
|
public long | getWorkerCount()Returns the total number of currently active workers
synchronized (this) {
return threadcount;
}
|
public void | interruptAll()Forcefully interrupt all workers
if (log.isDebugEnabled()) {
log.debug("Enter: ThreadPool::interruptAll");
}
synchronized (threads) {
for (Iterator i = threads.values().iterator(); i.hasNext();) {
Thread t = (Thread) i.next();
t.interrupt();
}
}
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::interruptAll");
}
|
public boolean | isShutdown()Returns true if all workers have been shutdown
synchronized (this) {
return _shutdown && threadcount == 0;
}
|
public boolean | isShuttingDown()Returns true if all workers are in the process of shutting down
synchronized (this) {
return _shutdown;
}
|
public void | safeShutdown()Forcefully shutdown the pool
if (log.isDebugEnabled()) {
log.debug("Enter: ThreadPool::safeShutdown");
}
synchronized (this) {
_shutdown = true;
}
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::safeShutdown");
}
|
public void | shutdown()Forcefully shutdown the pool
if (log.isDebugEnabled()) {
log.debug("Enter: ThreadPool::shutdown");
}
synchronized (this) {
_shutdown = true;
}
interruptAll();
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::shutdown");
}
|
public void | workerDone(java.lang.Runnable worker, boolean restart)Used by MessageWorkers to notify the pool that it is done
if (log.isDebugEnabled()) {
log.debug("Enter: ThreadPool::workerDone");
}
synchronized(this) {
threads.remove(worker);
if (--threadcount == 0 && _shutdown) {
notifyAll();
}
if (!_shutdown && restart) {
addWorker(worker);
}
}
if (log.isDebugEnabled()) {
log.debug("Exit: ThreadPool::workerDone");
}
|