class Concurrent::FixedThreadPool
@!macro fixed_thread_pool
A thread pool that reuses a fixed number of threads operating off an unbounded queue. At any point, at most `num_threads` will be active processing tasks. 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 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-
Calls superclass method
# File lib/concurrent-ruby/concurrent/executor/fixed_thread_pool.rb, line 211 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