Class: MarchHare::ThreadPools
- Inherits:
-
Object
- Object
- MarchHare::ThreadPools
- Defined in:
- lib/march_hare/thread_pools.rb
Overview
A slighly more Ruby developer-friendly way of instantiating various JDK executors (thread pools).
Class Method Summary collapse
-
.dynamically_growing ⇒ Object
Returns a new thread pool (JDK executor) that will create new threads as needed.
-
.fixed_of_size(n) ⇒ Object
Returns a new thread pool (JDK executor) of a fixed size.
-
.single_threaded ⇒ Object
Returns a new thread pool (JDK executor) of a fixed size of 1.
Class Method Details
.dynamically_growing ⇒ Object
Returns a new thread pool (JDK executor) that will create new threads as needed.
28 29 30 |
# File 'lib/march_hare/thread_pools.rb', line 28 def self.dynamically_growing JavaConcurrent::Executors.new_cached_thread_pool end |
.fixed_of_size(n) ⇒ Object
Returns a new thread pool (JDK executor) of a fixed size.
10 11 12 13 14 15 |
# File 'lib/march_hare/thread_pools.rb', line 10 def self.fixed_of_size(n) raise ArgumentError.new("n must be a positive integer!") unless Integer === n raise ArgumentError.new("n must be a positive integer!") unless n > 0 JavaConcurrent::Executors.new_fixed_thread_pool(n) end |
.single_threaded ⇒ Object
Returns a new thread pool (JDK executor) of a fixed size of 1.
20 21 22 |
# File 'lib/march_hare/thread_pools.rb', line 20 def self.single_threaded JavaConcurrent::Executors.new_single_thread_executor end |