Class: Concurrent::JavaFixedThreadPool

Inherits:
JavaThreadPoolExecutor show all
Defined in:
lib/concurrent/executor/java_fixed_thread_pool.rb

Overview

Note:

When running on the JVM (JRuby) this class will inherit from ‘JavaFixedThreadPool`. On all other platforms it will inherit from `RubyFixedThreadPool`.

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`

Constant Summary

Constants inherited from JavaThreadPoolExecutor

Concurrent::JavaThreadPoolExecutor::DEFAULT_MAX_POOL_SIZE, Concurrent::JavaThreadPoolExecutor::DEFAULT_MAX_QUEUE_SIZE, Concurrent::JavaThreadPoolExecutor::DEFAULT_MIN_POOL_SIZE, Concurrent::JavaThreadPoolExecutor::DEFAULT_THREAD_IDLETIMEOUT

Constants included from JavaExecutor

Concurrent::JavaExecutor::FALLBACK_POLICIES

Instance Attribute Summary

Attributes inherited from JavaThreadPoolExecutor

#max_length, #max_queue

Attributes included from Executor

#fallback_policy

Instance Method Summary collapse

Methods inherited from JavaThreadPoolExecutor

#can_overflow?, #completed_task_count, #idletime, #largest_length, #length, #min_length, #queue_length, #remaining_capacity, #running?, #scheduled_task_count, #status

Methods included from JavaExecutor

#<<, #kill, #post, #running?, #shutdown, #shutdown?, #shuttingdown?, #wait_for_termination

Methods included from Executor

#can_overflow?, #serialized?

Constructor Details

#initialize(num_threads, opts = {}) ⇒ JavaFixedThreadPool

Create a new thread pool.

Parameters:

  • opts (Hash) (defaults to: {})

    the options defining pool behavior.

Options Hash (opts):

  • :fallback_policy (Symbol) — default: `:abort`

    the fallback policy

Raises:

  • (ArgumentError)

    if ‘num_threads` is less than or equal to zero

  • (ArgumentError)

    if ‘fallback_policy` is not a known policy

See Also:



19
20
21
22
23
24
25
26
27
28
# File 'lib/concurrent/executor/java_fixed_thread_pool.rb', line 19

def initialize(num_threads, opts = {})

  opts = {
      min_threads: num_threads,
      max_threads: num_threads
  }.merge(opts)
  super(opts)

  set_shutdown_hook
end