org.eclipse.jetty.util.thread

## Class ExecutorThreadPool

- java.lang.Object
- - org.eclipse.jetty.util.component.AbstractLifeCycle
  - - org.eclipse.jetty.util.thread.ExecutorThreadPool

- All Implemented Interfaces:
    LifeCycle, ThreadPool

      public class ExecutorThreadPool
      extends AbstractLifeCycle
      implements ThreadPool, LifeCycle

  Jetty ThreadPool using java 5 ThreadPoolExecutor This class wraps a `ExecutorService` as a `ThreadPool` and `LifeCycle` interfaces so that it may be used by the Jetty `org.eclipse.jetty.server.Server`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `AbstractLifeCycle.AbstractLifeCycleListener`

    - ### Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.ThreadPool

      `ThreadPool.SizedThreadPool`

    - ### Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `LifeCycle.Listener`

  - ### Field Summary

    - ### Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExecutorThreadPool()` Wraps an `ThreadPoolExecutor`.
    `ExecutorThreadPool(ExecutorService executor)`
    `ExecutorThreadPool(int queueSize)` Wraps an `ThreadPoolExecutor`.
    `ExecutorThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime)` Wraps an `ThreadPoolExecutor` using an unbounded `LinkedBlockingQueue` is used for the jobs queue;
    `ExecutorThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit)` Wraps an `ThreadPoolExecutor` using an unbounded `LinkedBlockingQueue` is used for the jobs queue.
    `ExecutorThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue)` Wraps an `ThreadPoolExecutor`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `dispatch(Runnable job)`
    `protected void` | `doStop()`
    `int` | `getIdleThreads()`
    `int` | `getThreads()`
    `boolean` | `isLowOnThreads()`
    `void` | `join()` Blocks until the thread pool is `stopped`.

    - ### Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `addLifeCycleListener, doStart, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

- - ### Constructor Detail

    - #### ExecutorThreadPool

          public ExecutorThreadPool(ExecutorService executor)

    - #### ExecutorThreadPool

          public ExecutorThreadPool()

      Wraps an `ThreadPoolExecutor`. Max pool size is 256, pool thread timeout after 60 seconds and an unbounded `LinkedBlockingQueue` is used for the job queue;

    - #### ExecutorThreadPool

          public ExecutorThreadPool(int queueSize)

      Wraps an `ThreadPoolExecutor`. Max pool size is 256, pool thread timeout after 60 seconds, and core pool size is 32 when queueSize >= 0.
      Parameters:
        `queueSize` - can be -1 for using an unbounded `LinkedBlockingQueue`, 0 for using a `SynchronousQueue`, greater than 0 for using a `ArrayBlockingQueue` of the given size.

    - #### ExecutorThreadPool

          public ExecutorThreadPool(int corePoolSize,
                            int maximumPoolSize,
                            long keepAliveTime)

      Wraps an `ThreadPoolExecutor` using an unbounded `LinkedBlockingQueue` is used for the jobs queue;
      Parameters:
        `corePoolSize` - must be equal to maximumPoolSize
        `maximumPoolSize` - the maximum number of threads to allow in the pool
        `keepAliveTime` - the max time a thread can remain idle, in milliseconds

    - #### ExecutorThreadPool

          public ExecutorThreadPool(int corePoolSize,
                            int maximumPoolSize,
                            long keepAliveTime,
                            TimeUnit unit)

      Wraps an `ThreadPoolExecutor` using an unbounded `LinkedBlockingQueue` is used for the jobs queue.
      Parameters:
        `corePoolSize` - must be equal to maximumPoolSize
        `maximumPoolSize` - the maximum number of threads to allow in the pool
        `keepAliveTime` - the max time a thread can remain idle
        `unit` - the unit for the keepAliveTime

    - #### ExecutorThreadPool

          public ExecutorThreadPool(int corePoolSize,
                            int maximumPoolSize,
                            long keepAliveTime,
                            TimeUnit unit,
                            BlockingQueue<Runnable> workQueue)

      Wraps an `ThreadPoolExecutor`
      Parameters:
        `corePoolSize` - the number of threads to keep in the pool, even if they are idle
        `maximumPoolSize` - the maximum number of threads to allow in the pool
        `keepAliveTime` - the max time a thread can remain idle
        `unit` - the unit for the keepAliveTime
        `workQueue` - the queue to use for holding tasks before they are executed

  - ### Method Detail

    - #### dispatch

          public boolean dispatch(Runnable job)

      Specified by:
        `dispatch` in interface `ThreadPool`

    - #### getIdleThreads

          public int getIdleThreads()

      Specified by:
        `getIdleThreads` in interface `ThreadPool`
      Returns:
        The number of idle threads in the pool

    - #### getThreads

          public int getThreads()

      Specified by:
        `getThreads` in interface `ThreadPool`
      Returns:
        The total number of threads currently in the pool

    - #### isLowOnThreads

          public boolean isLowOnThreads()

      Specified by:
        `isLowOnThreads` in interface `ThreadPool`
      Returns:
        True if the pool is low on threads

    - #### join

          public void join()
                    throws InterruptedException

      Description copied from interface: `ThreadPool`
      Blocks until the thread pool is `stopped`.
      Specified by:
        `join` in interface `ThreadPool`
      Throws:
        `InterruptedException`

    - #### doStop

          protected void doStop()
                         throws Exception

      Overrides:
        `doStop` in class `AbstractLifeCycle`
      Throws:
        `Exception`

Copyright © 1995-2016 Mort Bay Consulting. All Rights Reserved.