Class: Concurrent::RubySingleThreadExecutor
- Inherits:
-
Object
- Object
- Concurrent::RubySingleThreadExecutor
- Includes:
- RubyExecutor, SerialExecutor
- Defined in:
- lib/concurrent/executor/ruby_single_thread_executor.rb
Overview
When running on the JVM (JRuby) this class will inherit from ‘JavaSingleThreadExecutor`. On all other platforms it will inherit from `RubySingleThreadExecutor`.
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 ‘SingleThreadExecutor`
Direct Known Subclasses
Constant Summary
Constants included from RubyExecutor
Concurrent::RubyExecutor::FALLBACK_POLICIES
Instance Attribute Summary
Attributes included from Executor
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ RubySingleThreadExecutor
constructor
Create a new thread pool.
Methods included from SerialExecutor
Methods included from Executor
Methods included from RubyExecutor
#<<, #kill, #post, #running?, #shutdown, #shutdown?, #shuttingdown?, #wait_for_termination
Methods included from Logging
Constructor Details
#initialize(opts = {}) ⇒ RubySingleThreadExecutor
Create a new thread pool.
19 20 21 22 23 24 25 |
# File 'lib/concurrent/executor/ruby_single_thread_executor.rb', line 19 def initialize(opts = {}) @queue = Queue.new @thread = nil @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICIES.include?(@fallback_policy) init_executor end |