Class: MarchHare::ThreadPools

Inherits:
Object
  • Object
show all
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)

Class Method Details

+ (Object) dynamically_growing

Returns a new thread pool (JDK executor) that will create new threads as needed.

Returns:

  • A thread pool (JDK executor)



28
29
30
# File 'lib/march_hare/thread_pools.rb', line 28

def self.dynamically_growing
  JavaConcurrent::Executors.new_cached_thread_pool
end

+ (Object) fixed_of_size(n)

Returns a new thread pool (JDK executor) of a fixed size.

Returns:

  • A thread pool (JDK executor)

Raises:

  • (ArgumentError)


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

+ (Object) single_threaded

Returns a new thread pool (JDK executor) of a fixed size of 1.

Returns:

  • A thread pool (JDK executor)



20
21
22
# File 'lib/march_hare/thread_pools.rb', line 20

def self.single_threaded
  JavaConcurrent::Executors.new_single_thread_executor
end