Methods

Files

Class/Module Index [+]

Quicksearch

Concurrent::FixedThreadPool

@!macro [attach] fixed_thread_pool

A thread pool with a set number of threads. The number of threads in the pool
is set on construction and remains constant. When all threads are busy new
tasks `#post` to the thread pool are enqueued until a thread becomes available.
Should a thread crash for any reason the thread will immediately be removed
from the pool and replaced.

The API and behavior of this class are based on Java's `FixedThreadPool`

@!macro thread_pool_options

Public Class Methods

new(num_threads, opts = {}) click to toggle source

@!macro [attach] fixed_thread_pool_method_initialize

Create a new thread pool.

@param [Integer] num_threads the number of threads to allocate
@param [Hash] opts the options defining pool behavior.
@option opts [Symbol] :fallback_policy (`:abort`) the fallback policy

@raise [ArgumentError] if `num_threads` is less than or equal to zero
@raise [ArgumentError] if `fallback_policy` is not a known policy

@see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool-int-
# File lib/concurrent/executor/fixed_thread_pool.rb, line 197
def initialize(num_threads, opts = {})
  raise ArgumentError.new('number of threads must be greater than zero') if num_threads.to_i < 1
  defaults  = { max_queue:   DEFAULT_MAX_QUEUE_SIZE,
                idletime:    DEFAULT_THREAD_IDLETIMEOUT }
  overrides = { min_threads: num_threads,
                max_threads: num_threads }
  super(defaults.merge(opts).merge(overrides))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.