Sha256: 82e3dffed11be27e6eb8b806a65f6de198e4c748f81292d1b9b4385858744477

Contents?: true

Size: 977 Bytes

Versions: 2

Compression:

Stored size: 977 Bytes

Contents

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

2 entries across 2 versions & 1 rubygems

Version Path
hot_bunnies-2.0.0.pre12-java lib/hot_bunnies/thread_pools.rb
hot_bunnies-2.0.0.pre11-java lib/hot_bunnies/thread_pools.rb