Sha256: 8c6ab46be24ca74656f5cafd5172928470a902b16f076236c973f7a5c4a56e42

Contents?: true

Size: 1002 Bytes

Versions: 30

Compression:

Stored size: 1002 Bytes

Contents

require "march_hare/juc"

module MarchHare
  # A slighly more Ruby developer-friendly way of instantiating various
  # JDK executors (thread pools).
  class ThreadPools
    # Returns a new thread pool (JDK executor) of a fixed size.
    #
    # @return A thread pool (JDK executor)
    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

    # Returns a new thread pool (JDK executor) of a fixed size of 1.
    #
    # @return A thread pool (JDK executor)
    def self.single_threaded
      JavaConcurrent::Executors.new_single_thread_executor
    end

    # Returns a new thread pool (JDK executor) that will create new
    # threads as needed.
    #
    # @return A thread pool (JDK executor)
    def self.dynamically_growing
      JavaConcurrent::Executors.new_cached_thread_pool
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
march_hare-3.0.0-java lib/march_hare/thread_pools.rb
march_hare-2.22.0-java lib/march_hare/thread_pools.rb
march_hare-2.21.0-java lib/march_hare/thread_pools.rb
march_hare-2.20.0-java lib/march_hare/thread_pools.rb
march_hare-2.19.0-java lib/march_hare/thread_pools.rb
march_hare-2.18.0-java lib/march_hare/thread_pools.rb
march_hare-2.17.0-java lib/march_hare/thread_pools.rb
march_hare-2.16.0-java lib/march_hare/thread_pools.rb
march_hare-2.15.0-java lib/march_hare/thread_pools.rb
march_hare-2.13.0-java lib/march_hare/thread_pools.rb
march_hare-2.12.0-java lib/march_hare/thread_pools.rb
march_hare-2.11.0-java lib/march_hare/thread_pools.rb
march_hare-2.10.0-java lib/march_hare/thread_pools.rb
march_hare-2.9.0-java lib/march_hare/thread_pools.rb
march_hare-2.8.0-java lib/march_hare/thread_pools.rb
march_hare-2.7.0-java lib/march_hare/thread_pools.rb
march_hare-2.5.1-java lib/march_hare/thread_pools.rb
march_hare-2.5.0-java lib/march_hare/thread_pools.rb
march_hare-2.4.0-java lib/march_hare/thread_pools.rb
march_hare-2.3.0-java lib/march_hare/thread_pools.rb