Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jasig.portal.utils
Class ThreadPool

    java.lang.Object
      java.lang.ThreadGroup
          org.jasig.portal.utils.ThreadPool

All Implemented Interfaces:
  java.lang.Thread.UncaughtExceptionHandler

    public class ThreadPool

extends java.lang.ThreadGroup

A thread pool implementation with a few extra kinks, such as ThreadPoolReceipt.

Version:
  $Revision: 1.12 $
Author:
  Peter Kharchenko pkharchenko@interactivebusiness.com

Field Summary
`(package private) BlockingStack` | `idleWorkers`
`(package private) ResourceLimits` | `limits`
`private static org.apache.commons.logging.Log` | `log`
`(package private) java.util.List` | `workers`

Constructor Summary
`ThreadPool(java.lang.String name, ResourceLimits rl)`

Method Summary
`protected void` | `addNewWorker()` Adds a new worker.
`protected void` | `addWorker()` Grow the size of the worker pool.
`protected void` | `adjustSize(int newSize)` Adjust the size of the worker pool.
`void` | `clear()` Clears all of the workers.
`void` | `clearIdle()` Clears all of the idle workers
`ThreadPoolReceipt` | `execute(java.lang.Runnable target)`
`protected void` | `killWorkerThread(ThreadPoolWorker pw)`
`protected void` | `notifyWorkerFinished(ThreadPoolWorker pw)` Notifies the pool that a certain worker has finished.
`protected void` | `notifyWorkerRestart(ThreadPoolWorker pw)` Notifies the pool that a certain worker is done and wants to have a replacement started.
`protected boolean` | `releaseWorker(ThreadPoolWorker worker)` Signals the worker that it should quite as soon as a job (if any) is complete
`protected void` | `stopWorker(ThreadPoolWorker worker)` Signals the worker that it try to interrupt the current job and quit.
`void` | `uncaughtException(java.lang.Thread t, java.lang.Throwable e)` Handle the case when some worker crashes

Methods inherited from class java.lang.ThreadGroup
`activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### log

    private static final org.apache.commons.logging.Log log

### idleWorkers

    BlockingStack idleWorkers

### workers

    java.util.List workers

### limits

    ResourceLimits limits

Constructor Detail

### ThreadPool

    public ThreadPool(java.lang.String name,
                      ResourceLimits rl)

Method Detail

### execute

    public ThreadPoolReceipt execute(java.lang.Runnable target)
                              throws java.lang.InterruptedException

  Throws:
    `java.lang.InterruptedException`

### adjustSize

    protected void adjustSize(int newSize)

  Adjust the size of the worker pool. Adjustment is done by growing/shrinking the idle worker pool. Active workers will not be affected by this

### addWorker

    protected void addWorker()

  Grow the size of the worker pool. This will "attempt" to add another worker, but unlike addNewWorker(), the resource limits are checked.

### stopWorker

    protected void stopWorker(ThreadPoolWorker worker)

  Signals the worker that it try to interrupt the current job and quit.

### releaseWorker

    protected boolean releaseWorker(ThreadPoolWorker worker)

  Signals the worker that it should quite as soon as a job (if any) is complete

  Returns:
    false if the worker has already been released

### addNewWorker

    protected void addNewWorker()

  Adds a new worker. Doesn't check anything, just adds.

### clearIdle

    public void clearIdle()

  Clears all of the idle workers

### clear

    public void clear()

  Clears all of the workers.

### uncaughtException

    public void uncaughtException(java.lang.Thread t,
                                  java.lang.Throwable e)

  Handle the case when some worker crashes

  Specified by:
    `uncaughtException` in interface `java.lang.Thread.UncaughtExceptionHandler`
  Overrides:
    `uncaughtException` in class `java.lang.ThreadGroup`

### notifyWorkerRestart

    protected void notifyWorkerRestart(ThreadPoolWorker pw)

  Notifies the pool that a certain worker is done and wants to have a replacement started.

### killWorkerThread

    protected void killWorkerThread(ThreadPoolWorker pw)

### notifyWorkerFinished

    protected void notifyWorkerFinished(ThreadPoolWorker pw)

  Notifies the pool that a certain worker has finished.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD