org.eclipse.jetty.util.thread

## Class QueuedThreadPool

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

- All Implemented Interfaces:
    Executor, Dumpable, LifeCycle, ThreadPool, ThreadPool.SizedThreadPool

      public class QueuedThreadPool
      extends AbstractLifeCycle
      implements ThreadPool.SizedThreadPool, Executor, Dumpable

- - ### 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
    `QueuedThreadPool()` Construct
    `QueuedThreadPool(BlockingQueue<Runnable> jobQ)` Construct
    `QueuedThreadPool(int maxThreads)` Construct

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `dispatch(Runnable job)`
    `protected void` | `doStart()`
    `protected void` | `doStop()`
    `String` | `dump()`
    `void` | `dump(Appendable out, String indent)`
    `String` | `dumpThread(long id)`
    `void` | `execute(Runnable job)`
    `int` | `getIdleThreads()`
    `int` | `getMaxIdleTimeMs()` Get the maximum thread idle time.
    `int` | `getMaxQueued()`
    `int` | `getMaxStopTimeMs()`
    `int` | `getMaxThreads()` Set the maximum number of threads.
    `int` | `getMinThreads()` Get the minimum number of threads.
    `String` | `getName()`
    `protected BlockingQueue<Runnable>` | `getQueue()`
    `int` | `getThreads()`
    `int` | `getThreadsPriority()` Get the priority of the pool threads.
    `boolean` | `interruptThread(long id)`
    `boolean` | `isDaemon()` Delegated to the named or anonymous Pool.
    `boolean` | `isDetailedDump()`
    `boolean` | `isLowOnThreads()`
    `void` | `join()` Blocks until the thread pool is `stopped`.
    `protected Thread` | `newThread(Runnable runnable)`
    `protected void` | `runJob(Runnable job)` Runs the given job in the `current thread`.
    `void` | `setDaemon(boolean daemon)` Delegated to the named or anonymous Pool.
    `void` | `setDetailedDump(boolean detailedDump)`
    `void` | `setMaxIdleTimeMs(int maxIdleTimeMs)` Set the maximum thread idle time.
    `void` | `setMaxQueued(int max)`
    `void` | `setMaxStopTimeMs(int stopTimeMs)`
    `void` | `setMaxThreads(int maxThreads)` Set the maximum number of threads.
    `void` | `setMinThreads(int minThreads)` Set the minimum number of threads.
    `void` | `setName(String name)`
    `void` | `setThreadsPriority(int priority)` Set the priority of the pool threads.
    `boolean` | `stopThread(long id)` Deprecated. Use `interruptThread(long)` in preference
    `String` | `toString()`

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

      `addLifeCycleListener, 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, wait, wait, wait`

- - ### Constructor Detail

    - #### QueuedThreadPool

          public QueuedThreadPool()

      Construct

    - #### QueuedThreadPool

          public QueuedThreadPool(int maxThreads)

      Construct

    - #### QueuedThreadPool

          public QueuedThreadPool(BlockingQueue<Runnable> jobQ)

      Construct

  - ### Method Detail

    - #### doStart

          protected void doStart()
                          throws Exception

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

    - #### doStop

          protected void doStop()
                         throws Exception

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

    - #### setDaemon

          public void setDaemon(boolean daemon)

      Delegated to the named or anonymous Pool.

    - #### setMaxIdleTimeMs

          public void setMaxIdleTimeMs(int maxIdleTimeMs)

      Set the maximum thread idle time. Threads that are idle for longer than this period may be stopped. Delegated to the named or anonymous Pool.
      Parameters:
        `maxIdleTimeMs` - Max idle time in ms.
      See Also:
        `getMaxIdleTimeMs()`

    - #### setMaxStopTimeMs

          public void setMaxStopTimeMs(int stopTimeMs)

      Parameters:
        `stopTimeMs` - maximum total time that stop() will wait for threads to die.

    - #### setMaxThreads

          public void setMaxThreads(int maxThreads)

      Set the maximum number of threads. Delegated to the named or anonymous Pool.
      Specified by:
        `setMaxThreads` in interface `ThreadPool.SizedThreadPool`
      Parameters:
        `maxThreads` - maximum number of threads.
      See Also:
        `getMaxThreads()`

    - #### setMinThreads

          public void setMinThreads(int minThreads)

      Set the minimum number of threads. Delegated to the named or anonymous Pool.
      Specified by:
        `setMinThreads` in interface `ThreadPool.SizedThreadPool`
      Parameters:
        `minThreads` - minimum number of threads
      See Also:
        `getMinThreads()`

    - #### setName

          public void setName(String name)

      Parameters:
        `name` - Name of the BoundedThreadPool to use when naming Threads.

    - #### setThreadsPriority

          public void setThreadsPriority(int priority)

      Set the priority of the pool threads.
      Parameters:
        `priority` - the new thread priority.

    - #### getMaxQueued

          public int getMaxQueued()

      Returns:
        maximum queue size

    - #### setMaxQueued

          public void setMaxQueued(int max)

      Parameters:
        `max` - job queue size

    - #### getMaxIdleTimeMs

          public int getMaxIdleTimeMs()

      Get the maximum thread idle time. Delegated to the named or anonymous Pool.
      Returns:
        Max idle time in ms.
      See Also:
        `setMaxIdleTimeMs(int)`

    - #### getMaxStopTimeMs

          public int getMaxStopTimeMs()

      Returns:
        maximum total time that stop() will wait for threads to die.

    - #### getMaxThreads

          public int getMaxThreads()

      Set the maximum number of threads. Delegated to the named or anonymous Pool.
      Specified by:
        `getMaxThreads` in interface `ThreadPool.SizedThreadPool`
      Returns:
        maximum number of threads.
      See Also:
        `setMaxThreads(int)`

    - #### getMinThreads

          public int getMinThreads()

      Get the minimum number of threads. Delegated to the named or anonymous Pool.
      Specified by:
        `getMinThreads` in interface `ThreadPool.SizedThreadPool`
      Returns:
        minimum number of threads.
      See Also:
        `setMinThreads(int)`

    - #### getName

          public String getName()

      Returns:
        The name of the BoundedThreadPool.

    - #### getThreadsPriority

          public int getThreadsPriority()

      Get the priority of the pool threads.
      Returns:
        the priority of the pool threads.

    - #### isDaemon

          public boolean isDaemon()

      Delegated to the named or anonymous Pool.

    - #### isDetailedDump

          public boolean isDetailedDump()

    - #### setDetailedDump

          public void setDetailedDump(boolean detailedDump)

    - #### dispatch

          public boolean dispatch(Runnable job)

      Specified by:
        `dispatch` in interface `ThreadPool`

    - #### execute

          public void execute(Runnable job)

      Specified by:
        `execute` in interface `Executor`

    - #### join

          public void join()
                    throws InterruptedException

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

    - #### getThreads

          public int getThreads()

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

    - #### getIdleThreads

          public int getIdleThreads()

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

    - #### isLowOnThreads

          public boolean isLowOnThreads()

      Specified by:
        `isLowOnThreads` in interface `ThreadPool`
      Returns:
        True if the pool is at maxThreads and there are not more idle threads than queued jobs

    - #### newThread

          protected Thread newThread(Runnable runnable)

    - #### dump

          public String dump()

      Specified by:
        `dump` in interface `Dumpable`

    - #### dump

          public void dump(Appendable out,
                  String indent)
                    throws IOException

      Specified by:
        `dump` in interface `Dumpable`
      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### runJob

          protected void runJob(Runnable job)

      Runs the given job in the `current thread`.

      Subclasses may override to perform pre/post actions before/after the job is run.

      Parameters:
        `job` - the job to run

    - #### getQueue

          protected BlockingQueue<Runnable> getQueue()

      Returns:
        the job queue

    - #### stopThread

          @Deprecated
          public boolean stopThread(long id)

      Deprecated. Use `interruptThread(long)` in preference
      Parameters:
        `id` - The thread ID to stop.
      Returns:
        true if the thread was found and stopped.

    - #### interruptThread

          public boolean interruptThread(long id)

      Parameters:
        `id` - The thread ID to interrupt.
      Returns:
        true if the thread was found and interrupted.

    - #### dumpThread

          public String dumpThread(long id)

      Parameters:
        `id` - The thread ID to interrupt.
      Returns:
        true if the thread was found and interrupted.

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