Class: Concurrent::JavaSingleThreadExecutor
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Concurrent::JavaExecutorService
|
Defined in: | lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb |
Overview
A thread pool with a single thread an unlimited queue. Should the thread die for any reason it will be removed and replaced, thus ensuring that the executor will always remain viable and available to process jobs.
A common pattern for background processing is to create a single thread on which an infinite loop is run. The thread’s loop blocks on an input source (perhaps blocking I/O or a queue) and processes each input as it is received. This pattern has several issues. The thread itself is highly susceptible to errors during processing. Also, the thread itself must be constantly monitored and restarted should it die. SingleThreadExecutor
encapsulates all these bahaviors. The task processor is highly resilient to errors from within tasks. Also, should the thread die it will automatically be restarted.
The API and behavior of this class are based on Java’s SingleThreadExecutor
.
Constant Summary
Class Method Summary
-
.new(opts = {}) ⇒ JavaSingleThreadExecutor
constructor
Create a new thread pool.
AbstractExecutorService
- Inherited
.new | Create a new thread pool. |
Instance Attribute Summary
- #fallback_policy ⇒ Symbol readonly
SerialExecutorService
- Included
#serialized? | Does this executor guarantee serialization of its operations? |
JavaExecutorService
- Inherited
AbstractExecutorService
- Inherited
#auto_terminate= |
|
#auto_terminate? | Is the executor auto-terminate when the application exits? |
#fallback_policy, #name, | |
#running? | Is the executor running? |
#shutdown | Begin an orderly shutdown. |
#shutdown? | Is the executor shutdown? |
#shuttingdown? | Is the executor shuttingdown? |
#ns_auto_terminate? |
ExecutorService
- Included
#can_overflow? | Does the task queue have a maximum size? |
#serialized? | Does this executor guarantee serialization of its operations? |
Instance Method Summary
-
#<<(task) ⇒ self
Submit a task to the executor for asynchronous processing.
-
#auto_terminate=(value) ⇒ Boolean
deprecated
Deprecated.
Has no effect
-
#auto_terminate? ⇒ Boolean
Is the executor auto-terminate when the application exits?
-
#can_overflow? ⇒ Boolean
Does the task queue have a maximum size?
-
#kill
Begin an immediate shutdown.
-
#post(*args) { ... } ⇒ Boolean
Submit a task to the executor for asynchronous processing.
-
#running? ⇒ Boolean
Is the executor running?
-
#serialized? ⇒ Boolean
Does this executor guarantee serialization of its operations?
-
#shutdown
Begin an orderly shutdown.
-
#shutdown? ⇒ Boolean
Is the executor shutdown?
-
#shuttingdown? ⇒ Boolean
Is the executor shuttingdown?
-
#wait_for_termination(timeout = nil) ⇒ Boolean
Block until executor shutdown is complete or until
timeout
seconds have passed. - #ns_initialize(opts) private
JavaExecutorService
- Inherited
#<< | Submit a task to the executor for asynchronous processing. |
#auto_terminate= |
|
#auto_terminate? | Is the executor auto-terminate when the application exits? |
#can_overflow? | Does the task queue have a maximum size? |
#kill | Begin an immediate shutdown. |
#post | Submit a task to the executor for asynchronous processing. |
#running? | Is the executor running? |
#serialized? | Does this executor guarantee serialization of its operations? |
#shutdown | Begin an orderly shutdown. |
#shutdown? | Is the executor shutdown? |
#shuttingdown? | Is the executor shuttingdown? |
#wait_for_termination | Block until executor shutdown is complete or until |
AbstractExecutorService
- Inherited
#<< | Submit a task to the executor for asynchronous processing. |
#can_overflow? | Does the task queue have a maximum size? |
#kill | Begin an immediate shutdown. |
#post | Submit a task to the executor for asynchronous processing. |
#serialized? | Does this executor guarantee serialization of its operations? |
#to_s, | |
#wait_for_termination | Block until executor shutdown is complete or until |
#fallback_action | Returns an action which executes the #fallback_policy once the queue size reaches |
#ns_execute, | |
#ns_kill_execution | Callback method called when the executor has been killed. |
#ns_shutdown_execution | Callback method called when an orderly shutdown has completed. |
Concern::Deprecation
- Included
ExecutorService
- Included
#<< | Submit a task to the executor for asynchronous processing. |
#post | Submit a task to the executor for asynchronous processing. |
Concern::Logging
- Included
#log | Logs through global_logger, it can be overridden by setting @logger. |
Synchronization::LockableObject
- Inherited
Constructor Details
.new(opts = {}) ⇒ JavaSingleThreadExecutor
Create a new thread pool.
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 15
def initialize(opts = {}) super(opts) end
Instance Attribute Details
#fallback_policy ⇒ Symbol
(readonly)
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
Instance Method Details
#<<(task) ⇒ self
Submit a task to the executor for asynchronous processing.
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#auto_terminate=(value) ⇒ Boolean
Has no effect
Set
the auto-terminate behavior for this executor.
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#auto_terminate? ⇒ Boolean
Is the executor auto-terminate when the application exits?
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#can_overflow? ⇒ Boolean
Does the task queue have a maximum size?
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#kill
Begin an immediate shutdown. In-progress tasks will be allowed to complete but enqueued tasks will be dismissed and no new tasks will be accepted. Has no additional effect if the thread pool is not running.
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#ns_initialize(opts) (private)
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 21
def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end
#post(*args) { ... } ⇒ Boolean
Submit a task to the executor for asynchronous processing.
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#running? ⇒ Boolean
Is the executor running?
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#serialized? ⇒ Boolean
Does this executor guarantee serialization of its operations?
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#shutdown
Begin an orderly shutdown. Tasks already in the queue will be executed, but no new tasks will be accepted. Has no additional effect if the thread pool is not running.
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#shutdown? ⇒ Boolean
Is the executor shutdown?
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#shuttingdown? ⇒ Boolean
Is the executor shuttingdown?
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end
#wait_for_termination(timeout = nil) ⇒ Boolean
# File 'lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb', line 11
class JavaSingleThreadExecutor < JavaExecutorService include SerialExecutorService # @!macro single_thread_executor_method_initialize def initialize(opts = {}) super(opts) end private def ns_initialize(opts) @executor = java.util.concurrent.Executors.newSingleThreadExecutor( DaemonThreadFactory.new(ns_auto_terminate?) ) @fallback_policy = opts.fetch(:fallback_policy, :discard) raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy) end end