# Class: Concurrent::ThreadPoolExecutor

Inherits:
  ThreadPoolExecutorImplementation
  - Object
  - Concurrent::ThreadPoolExecutor
  show all

Defined in:
  lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb

## Overview

Note:

Failure to properly shutdown a thread pool can lead to unpredictable results. Please read Shutting Down Thread Pools for more information.

An abstraction composed of one or more threads and a task queue. Tasks (blocks or `proc` objects) are submitted to the pool and added to the queue. The threads in the pool remove the tasks and execute them in the order they were received.

A `ThreadPoolExecutor` will automatically adjust the pool size according to the bounds set by `min-threads` and `max-threads`. When a new task is submitted and fewer than `min-threads` threads are running, a new thread is created to handle the request, even if other worker threads are idle. If there are more than `min-threads` but less than `max-threads` threads running, a new thread will be created only if the queue is full.

Threads that are idle for too long will be garbage collected, down to the configured minimum options. Should a thread crash it, too, will be garbage collected.

`ThreadPoolExecutor` is based on the Java class of the same name. From the official Java documentation;

> Thread pools address two different problems: they usually provide improved performance when executing large numbers of asynchronous tasks, due to reduced per-task invocation overhead, and they provide a means of bounding and managing the resources, including threads, consumed when executing a collection of tasks. Each ThreadPoolExecutor also maintains some basic statistics, such as the number of completed tasks.

> To be useful across a wide range of contexts, this class provides many adjustable parameters and extensibility hooks. However, programmers are urged to use the more convenient Executors factory methods CachedThreadPool, FixedThreadPool and SingleThreadExecutor, that preconfigure settings for the most common usage scenarios.

Thread Pool Options

Thread pools support several configuration options:

- `idletime`: The number of seconds that a thread may be idle before being reclaimed.
- `name`: The name of the executor (optional). Printed in the executor's `#to_s` output and a `<name>-worker-<id>` name is given to its threads if supported by used Ruby implementation. `<id>` is uniq for each thread.
- `max_queue`: The maximum number of tasks that may be waiting in the work queue at any one time. When the queue size reaches `max_queue` and no new threads can be created, subsequent tasks will be rejected in accordance with the configured `fallback_policy`.
- `auto_terminate`: When true (default), the threads started will be marked as daemon.
- `fallback_policy`: The policy defining how rejected tasks are handled.

Three fallback policies are supported:

- `:abort`: Raise a `RejectedExecutionError` exception and discard the task.
- `:discard`: Discard the task and return false.
- `:caller_runs`: Execute the task on the calling thread.

Shutting Down Thread Pools

Killing a thread pool while tasks are still being processed, either by calling the `#kill` method or at application exit, will have unpredictable results. There is no way for the thread pool to know what resources are being used by the in-progress tasks. When those tasks are killed the impact on those resources cannot be predicted. The best practice is to explicitly shutdown all thread pools using the provided methods:

- Call `#shutdown` to initiate an orderly termination of all in-progress tasks
- Call `#wait_for_termination` with an appropriate timeout interval an allow the orderly shutdown to complete
- Call `#kill` only when the thread pool fails to shutdown in the allotted time

On some runtime platforms (most notably the JVM) the application will not exit until all thread pools have been shutdown. To prevent applications from "hanging" on exit, all threads can be marked as daemon according to the `:auto_terminate` option.

    pool1 = Concurrent::FixedThreadPool.new(5) # threads will be marked as daemon
    pool2 = Concurrent::FixedThreadPool.new(5, auto_terminate: false) # mark threads as non-daemon

See Also:

- Java Tutorials: Thread Pools
- Java Executors class
- Java ExecutorService interface
- https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#setDaemon-boolean-

## Direct Known Subclasses

CachedThreadPool, FixedThreadPool

## Instance Attribute Summary collapse

- #completed_task_count ⇒ Integer readonly

  The number of tasks that have been completed by the pool since construction.

- #fallback_policy ⇒ Symbol readonly

  The fallback policy in effect.

- #idletime ⇒ Integer readonly

  The number of seconds that a thread may be idle before being reclaimed.

- #largest_length ⇒ Integer readonly

  The largest number of threads that have been created in the pool since construction.

- #length ⇒ Integer readonly

  The number of threads currently in the pool.

- #max_length ⇒ Integer readonly

  The maximum number of threads that may be created in the pool.

- #max_queue ⇒ Integer readonly

  The maximum number of tasks that may be waiting in the work queue at any one time.

- #min_length ⇒ Integer readonly

  The minimum number of threads that may be retained in the pool.

- #queue_length ⇒ Integer readonly

  The number of tasks in the queue awaiting execution.

- #remaining_capacity ⇒ Integer readonly

  Number of tasks that may be enqueued before reaching `max_queue` and rejecting new tasks.

- #scheduled_task_count ⇒ Integer readonly

  The number of tasks that have been scheduled for execution on the pool since construction.

## Instance Method Summary collapse

- #<<(task) ⇒ self

  Submit a task to the executor for asynchronous processing.

- #auto_terminate=(value) ⇒ Boolean deprecated Deprecated.

  Has no effect

- #auto_terminate? ⇒ Boolean

  Is the executor auto-terminate when the application exits?.

- #can_overflow? ⇒ Boolean

  Does the task queue have a maximum size?.

- #kill ⇒ undocumented

  Begin an immediate shutdown.

- #post(*args) { ... } ⇒ Boolean

  Submit a task to the executor for asynchronous processing.

- #running? ⇒ Boolean

  Is the executor running?.

- #serialized? ⇒ Boolean

  Does this executor guarantee serialization of its operations?.

- #shutdown ⇒ undocumented

  Begin an orderly shutdown.

- #shutdown? ⇒ Boolean

  Is the executor shutdown?.

- #shuttingdown? ⇒ Boolean

  Is the executor shuttingdown?.

- #wait_for_termination(timeout = nil) ⇒ Boolean

  Block until executor shutdown is complete or until `timeout` seconds have passed.

## Instance Attribute Details

### #completed_task_count ⇒ `Integer` (readonly)

The number of tasks that have been completed by the pool since construction.

Returns:

- (`Integer`) —

  The number of tasks that have been completed by the pool since construction.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #fallback_policy ⇒ `Symbol` (readonly)

Returns The fallback policy in effect. Either `:abort`, `:discard`, or `:caller_runs`.

Returns:

- (`Symbol`) —

  The fallback policy in effect. Either `:abort`, `:discard`, or `:caller_runs`.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #idletime ⇒ `Integer` (readonly)

The number of seconds that a thread may be idle before being reclaimed.

Returns:

- (`Integer`) —

  The number of seconds that a thread may be idle before being reclaimed.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #largest_length ⇒ `Integer` (readonly)

The largest number of threads that have been created in the pool since construction.

Returns:

- (`Integer`) —

  The largest number of threads that have been created in the pool since construction.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #length ⇒ `Integer` (readonly)

The number of threads currently in the pool.

Returns:

- (`Integer`) —

  The number of threads currently in the pool.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #max_length ⇒ `Integer` (readonly)

The maximum number of threads that may be created in the pool.

Returns:

- (`Integer`) —

  The maximum number of threads that may be created in the pool.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #max_queue ⇒ `Integer` (readonly)

The maximum number of tasks that may be waiting in the work queue at any one time. When the queue size reaches `max_queue` subsequent tasks will be rejected in accordance with the configured `fallback_policy`.

Returns:

- (`Integer`) —

  The maximum number of tasks that may be waiting in the work queue at any one time. When the queue size reaches `max_queue` subsequent tasks will be rejected in accordance with the configured `fallback_policy`.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #min_length ⇒ `Integer` (readonly)

The minimum number of threads that may be retained in the pool.

Returns:

- (`Integer`) —

  The minimum number of threads that may be retained in the pool.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #queue_length ⇒ `Integer` (readonly)

The number of tasks in the queue awaiting execution.

Returns:

- (`Integer`) —

  The number of tasks in the queue awaiting execution.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #remaining_capacity ⇒ `Integer` (readonly)

Number of tasks that may be enqueued before reaching `max_queue` and rejecting new tasks. A value of -1 indicates that the queue may grow without bound.

Returns:

- (`Integer`) —

  Number of tasks that may be enqueued before reaching `max_queue` and rejecting new tasks. A value of -1 indicates that the queue may grow without bound.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #scheduled_task_count ⇒ `Integer` (readonly)

The number of tasks that have been scheduled for execution on the pool since construction.

Returns:

- (`Integer`) —

  The number of tasks that have been scheduled for execution on the pool since construction.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

## Instance Method Details

### #<<(task) ⇒ `self`

Submit a task to the executor for asynchronous processing.

Parameters:

- task (`Proc`) —

  the asynchronous task to perform

Returns:

- (`self`) —

  returns itself

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #auto_terminate=(value) ⇒ `Boolean`

Deprecated.

Has no effect

Set the auto-terminate behavior for this executor.

Parameters:

- value (`Boolean`) —

  The new auto-terminate value to set for this executor.

Returns:

- (`Boolean`) —

  `true` when auto-termination is enabled else `false`.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #auto_terminate? ⇒ `Boolean`

Is the executor auto-terminate when the application exits?

Returns:

- (`Boolean`) —

  `true` when auto-termination is enabled else `false`.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #can_overflow? ⇒ `Boolean`

Does the task queue have a maximum size?

Returns:

- (`Boolean`) —

  True if the task queue has a maximum size else false.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #kill ⇒ `undocumented`

Begin an immediate shutdown. In-progress tasks will be allowed to complete but enqueued tasks will be dismissed and no new tasks will be accepted. Has no additional effect if the thread pool is not running.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #post(*args) { ... } ⇒ `Boolean`

Submit a task to the executor for asynchronous processing.

Parameters:

- args (`Array`) —

  zero or more arguments to be passed to the task

Yields:

- the asynchronous task to perform

Returns:

- (`Boolean`) —

  `true` if the task is queued, `false` if the executor is not running

Raises:

- (`ArgumentError`) —

  if no task is given

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #running? ⇒ `Boolean`

Is the executor running?

Returns:

- (`Boolean`) —

  `true` when running, `false` when shutting down or shutdown

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #serialized? ⇒ `Boolean`

Does this executor guarantee serialization of its operations?

Returns:

- (`Boolean`) —

  True if the executor guarantees that all operations will be post in the order they are received and no two operations may occur simultaneously. Else false.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #shutdown ⇒ `undocumented`

Begin an orderly shutdown. Tasks already in the queue will be executed, but no new tasks will be accepted. Has no additional effect if the thread pool is not running.

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #shutdown? ⇒ `Boolean`

Is the executor shutdown?

Returns:

- (`Boolean`) —

  `true` when shutdown, `false` when shutting down or running

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #shuttingdown? ⇒ `Boolean`

Is the executor shuttingdown?

Returns:

- (`Boolean`) —

  `true` when not running and not shutdown, else `false`

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end

### #wait_for_termination(timeout = nil) ⇒ `Boolean`

Note:

Does not initiate shutdown or termination. Either `shutdown` or `kill` must be called before this method (or on another thread).

Block until executor shutdown is complete or until `timeout` seconds have passed.

Parameters:

- timeout (`Integer`) (defaults to: `nil`) —

  the maximum number of seconds to wait for shutdown to complete

Returns:

- (`Boolean`) —

  `true` if shutdown complete or false on `timeout`

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    # File 'lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb', line 56

    class ThreadPoolExecutor < ThreadPoolExecutorImplementation

      # @!macro thread_pool_executor_method_initialize
      #
      #   Create a new thread pool.
      #
      #   @param [Hash] opts the options which configure the thread pool.
      #
      #   @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
      #     number of threads to be created
      #   @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
      #      and fewer than `min_threads` are running, a new thread is created
      #   @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
      #     number of seconds a thread may be idle before being reclaimed
      #   @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
      #     number of tasks allowed in the work queue at any one time; a value of
      #     zero means the queue may grow without bound
      #   @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
      #     tasks that are received when the queue size has reached
      #     `max_queue` or the executor has shut down
      #   @option opts [Boolean] :synchronous (DEFAULT_SYNCHRONOUS) whether or not a value of 0
      #     for :max_queue means the queue must perform direct hand-off rather than unbounded.
      #   @raise [ArgumentError] if `:max_threads` is less than one
      #   @raise [ArgumentError] if `:min_threads` is less than zero
      #   @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
      #     in `FALLBACK_POLICIES`
      #
      #   @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

      # @!method initialize(opts = {})
      #   @!macro thread_pool_executor_method_initialize
    end