class Concurrent::CachedThreadPool

@!macro thread_pool_options
The API and behavior of this class are based on Java’s ‘CachedThreadPool`
efficient at reclaiming unused resources.
of time will be killed and reclaimed. Thus these thread pools are very
from the pool. Similarly, threads which remain idle for an extended period
Should a thread crash for any reason the thread will immediately be removed
with the new operation.
operation is post to the pool the first available idle thread will be tasked
of threads exceeds the number of running and pending operations. When a new
will grow until `#max_length` threads are in the pool or until the number
created on the pool as new operations are `#post`. The size of the pool
On creation a `CachedThreadPool` has zero running threads. New threads are
short-lived tasks.
pools are particularly suited to applications that perform a high volume of
that remain idle for too long are killed and removed from the pool. These
New threads are created as needed, existing threads are reused, and threads
A thread pool that dynamically grows and shrinks to fit the current workload.

def initialize(opts = {})

Other tags:
    See: http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool-- -

Raises:
  • (ArgumentError) - if `fallback_policy` is not a known policy

Options Hash: (**opts)
  • :fallback_policy (Symbol) -- the fallback policy

Parameters:
  • opts (Hash) -- the options defining pool behavior.
def initialize(opts = {})
  defaults  = { idletime: DEFAULT_THREAD_IDLETIMEOUT }
  overrides = { min_threads: 0,
                max_threads: DEFAULT_MAX_POOL_SIZE,
                max_queue:   DEFAULT_MAX_QUEUE_SIZE }
  super(defaults.merge(opts).merge(overrides))
end

def ns_initialize(opts)

@!visibility private
@!macro cached_thread_pool_method_initialize
def ns_initialize(opts)
  super(opts)
  if Concurrent.on_jruby?
    @max_queue          = 0
    @executor           = java.util.concurrent.Executors.newCachedThreadPool(
        DaemonThreadFactory.new(ns_auto_terminate?))
    @executor.setRejectedExecutionHandler(FALLBACK_POLICY_CLASSES[@fallback_policy].new)
    @executor.setKeepAliveTime(opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT), java.util.concurrent.TimeUnit::SECONDS)
  end
end