Class: Garcon::FixedThreadPool

Inherits:
ThreadPoolExecutor show all
Defined in:
lib/garcon/task/thread_pool/fixed.rb

Constant Summary

Constants inherited from ThreadPoolExecutor

ThreadPoolExecutor::DEFAULT_MAX_POOL_SIZE, ThreadPoolExecutor::DEFAULT_MAX_QUEUE_SIZE, ThreadPoolExecutor::DEFAULT_MIN_POOL_SIZE, ThreadPoolExecutor::DEFAULT_THREAD_IDLETIMEOUT

Constants included from RubyExecutor

RubyExecutor::FALLBACK_POLICY

Instance Attribute Summary

Attributes inherited from ThreadPoolExecutor

#completed_task_count, #idletime, #largest_length, #max_length, #max_queue, #min_length, #scheduled_task_count

Attributes included from Executor

#fallback_policy

Instance Method Summary collapse

Methods inherited from ThreadPoolExecutor

#can_overflow?, #length, #queue_length, #remaining_capacity, #status

Methods included from RubyExecutor

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

Methods included from Executor

#auto_terminate?, #can_overflow?, #serialized?

Constructor Details

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

Create a new thread pool.

Parameters:

  • num_threads (Integer)

    The number of threads to allocate.

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

    The options defining pool behavior.

Options Hash (opts):

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

    The fallback policy

Raises:

  • (ArgumentError)

    if ‘num_threads` is less than or equal to zero

  • (ArgumentError)

    if ‘fallback` is not a known policy



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/garcon/task/thread_pool/fixed.rb', line 42

def initialize(num_threads, opts = {})
  fallback = opts.fetch(:fallback, :abort)

  if num_threads < 1
    raise ArgumentError, 'number of threads must be greater than zero'
  elsif !FALLBACK_POLICY.include?(fallback)
    raise ArgumentError, "#{fallback} is not a valid fallback policy"
  end

  opts = opts.merge(
    min_threads: num_threads,
    max_threads: num_threads,
    fallback:    fallback,
    max_queue:   DEFAULT_MAX_QUEUE_SIZE,
    idletime:    DEFAULT_THREAD_IDLETIMEOUT)

  super(opts)
end