: Class ThreadPool

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

## com.mortbay.Util
Class ThreadPool

    java.lang.Object
      |
      +--com.mortbay.Util.ThreadPool

Direct Known Subclasses:
  IO

public class ThreadPool
extends java.lang.Object

A pool of threads.

Avoids the expense of thread creation by pooling threads after their run methods exit for reuse.

If the maximum pool size is reached, jobs wait for a free thread. By default there is no maximum pool size.

#### Usage

Works well with inner classes:

     final ArgClass myArg = new ArgClass(...);
     threadPool.run(new Runnable() { public void run() { myHandler(myArg); }} );

Version:
  $Id: ThreadPool.java,v 1.11 1999/09/22 15:08:39 gregw Exp $
Author:
  Juancarlo Aņez , Greg Wilkins

Constructor Summary
`ThreadPool()` Constructor.
`ThreadPool(int maxThreads)` Constructor.
`ThreadPool(int minThreads, int maxThreads, java.lang.String name, int maxIdleTimeMs)` Constructor.
`ThreadPool(int maxThreads, java.lang.String name)` Constructor.
`ThreadPool(int maxThreads, java.lang.String name, int maxIdleTimeMs)` Constructor.

Method Summary
`int` | `getMaxSize()`
`int` | `getMinSize()`
`int` | `getSize()`
`protected void` | `handle(java.lang.Object job)` Handle a job.
`void` | `run(java.lang.Object job)` Run job

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

Constructor Detail

### ThreadPool

    public ThreadPool()

  Constructor.

### ThreadPool

    public ThreadPool(int maxThreads)

  Constructor.
  Parameters:
    `maxThreads` - Maximum number of handler threads.

### ThreadPool

    public ThreadPool(int maxThreads,
                      java.lang.String name)

  Constructor.
  Parameters:
    `maxThreads` - Maximum number of handler threads.
    `name` - Name of the thread.

### ThreadPool

    public ThreadPool(int maxThreads,
                      java.lang.String name,
                      int maxIdleTimeMs)

  Constructor.
  Parameters:
    `maxThreads` - Maximum number of handler threads.
    `name` - Name of the thread.
    `maxIdleTimeMs` - Idle time in milliseconds before a handler thread dies.

### ThreadPool

    public ThreadPool(int minThreads,
                      int maxThreads,
                      java.lang.String name,
                      int maxIdleTimeMs)

  Constructor.
  Parameters:
    `minThreads` - Minimum number of handler threads.
    `maxThreads` - Maximum number of handler threads.
    `name` - Name of the thread
    `maxIdleTimeMs` - Idle time in milliseconds before a handler thread dies.

Method Detail

### getSize

    public int getSize()

### getMinSize

    public int getMinSize()

### getMaxSize

    public int getMaxSize()

### run

    public void run(java.lang.Object job)
             throws java.lang.InterruptedException

  Run job
  Parameters:
    `job.` - If the job is derived from Runnable, the run method is called, otherwise it is passed as the argument to the handle method.

### handle

    protected void handle(java.lang.Object job)

  Handle a job. Unless the job is an instance of Runnable, then this method must be specialized by a derived class.
  Parameters:
    `job` -

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