Class: Temporalio::Worker::WorkflowExecutor::ThreadPool

Inherits:
Temporalio::Worker::WorkflowExecutor show all
Defined in:
lib/temporalio/worker/workflow_executor/thread_pool.rb

Overview

Thread pool implementation of Temporalio::Worker::WorkflowExecutor.

Users should use ThreadPool.default unless they have specific needs to change the thread pool or max threads.

Defined Under Namespace

Classes: DeadlockError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_threads: [4, Etc.nprocessors].max, thread_pool: Temporalio::Worker::ThreadPool.default) ⇒ ThreadPool

Create a thread pool executor. Most users may prefer default.

Parameters:

  • max_threads (Integer) (defaults to: [4, Etc.nprocessors].max)

    Maximum number of threads to use concurrently.

  • thread_pool (Worker::ThreadPool) (defaults to: Temporalio::Worker::ThreadPool.default)

    Thread pool to use.



30
31
32
33
34
35
36
# File 'lib/temporalio/worker/workflow_executor/thread_pool.rb', line 30

def initialize(max_threads: [4, Etc.nprocessors].max, thread_pool: Temporalio::Worker::ThreadPool.default) # rubocop:disable Lint/MissingSuper
  @max_threads = max_threads
  @thread_pool = thread_pool
  @workers_mutex = Mutex.new
  @workers = []
  @workers_by_worker_state_and_run_id = {}
end

Class Method Details

.defaultThreadPool

Returns Default executor that lazily constructs an instance with default values.

Returns:

  • (ThreadPool)

    Default executor that lazily constructs an instance with default values.



22
23
24
# File 'lib/temporalio/worker/workflow_executor/thread_pool.rb', line 22

def self.default
  @default ||= ThreadPool.new
end