Sha256: 845730d649a6d61504217004dee64f447798564ed87b46d49e846ac494fcdb5b

Contents?: true

Size: 1004 Bytes

Versions: 1

Compression:

Stored size: 1004 Bytes

Contents

require "hot_bunnies/juc"

module HotBunnies
  # 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

1 entries across 1 versions & 1 rubygems

Version Path
hot_bunnies-2.0.0.pre13-java lib/hot_bunnies/thread_pools.rb