Sha256: 53bb463c62a7377f7e4b841ab4272a19b8b4f79c73fb21aa637350f78b5d5e54

Contents?: true

Size: 1.04 KB

Versions: 41

Compression:

Stored size: 1.04 KB

Contents

if RUBY_PLATFORM == 'java'

  require 'concurrent/executor/java_thread_pool_executor'

  module Concurrent

    # @!macro cached_thread_pool
    class JavaCachedThreadPool < JavaThreadPoolExecutor

      # Create a new thread pool.
      #
      # @param [Hash] opts the options defining pool behavior.
      # @option opts [Symbol] :overflow_policy (`:abort`) the overflow policy
      #
      # @raise [ArgumentError] if `overflow_policy` is not a known policy
      #
      # @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool--
      def initialize(opts = {})
        @overflow_policy = opts.fetch(:overflow_policy, :abort)
        @max_queue = 0

        raise ArgumentError.new("#{@overflow_policy} is not a valid overflow policy") unless OVERFLOW_POLICIES.keys.include?(@overflow_policy)

        @executor = java.util.concurrent.Executors.newCachedThreadPool
        @executor.setRejectedExecutionHandler(OVERFLOW_POLICIES[@overflow_policy].new)

        set_shutdown_hook
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
concurrent-ruby-0.7.1 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.1-x86_64-linux lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.1-x86-solaris-2.11 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.1-x86-mingw32 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.1-x86-linux lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.1-x64-mingw32 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.1-java lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0-x86_64-linux lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0-x86-solaris-2.11 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0-x86-mingw32 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0-x86-linux lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0-x64-mingw32 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0-java lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0.rc2 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0.rc2-x86_64-linux lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0.rc2-x86_64-darwin-13 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0.rc2-x86-solaris-2.11 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0.rc2-x86-mingw32 lib/concurrent/executor/java_cached_thread_pool.rb
concurrent-ruby-0.7.0.rc2-x86-linux lib/concurrent/executor/java_cached_thread_pool.rb