Class: Concurrent::CachedThreadPool

Inherits:
RubyCachedThreadPool show all
Defined in:
lib/concurrent/executor/cached_thread_pool.rb,
lib/concurrent/executor/cached_thread_pool.rb

Overview

Note:

When running on the JVM (JRuby) this class will inherit from ‘JavaCachedThreadPool`. On all other platforms it will inherit from `RubyCachedThreadPool`.

A thread pool that dynamically grows and shrinks to fit the current workload. New threads are created as needed, existing threads are reused, and threads that remain idle for too long are killed and removed from the pool. These pools are particularly suited to applications that perform a high volume of short-lived tasks.

On creation a ‘CachedThreadPool` has zero running threads. New threads are created on the pool as new operations are `#post`. The size of the pool will grow until `#max_length` threads are in the pool or until the number of threads exceeds the number of running and pending operations. When a new operation is post to the pool the first available idle thread will be tasked with the new operation.

Should a thread crash for any reason the thread will immediately be removed from the pool. Similarly, threads which remain idle for an extended period of time will be killed and reclaimed. Thus these thread pools are very efficient at reclaiming unused resources.

The API and behavior of this class are based on Java’s ‘CachedThreadPool`

Constant Summary

Constants inherited from RubyThreadPoolExecutor

RubyThreadPoolExecutor::DEFAULT_MAX_POOL_SIZE, RubyThreadPoolExecutor::DEFAULT_MAX_QUEUE_SIZE, RubyThreadPoolExecutor::DEFAULT_MIN_POOL_SIZE, RubyThreadPoolExecutor::DEFAULT_THREAD_IDLETIMEOUT, RubyThreadPoolExecutor::OVERFLOW_POLICIES

Instance Attribute Summary

Attributes inherited from RubyThreadPoolExecutor

#completed_task_count, #idletime, #largest_length, #max_length, #max_queue, #min_length, #overflow_policy, #scheduled_task_count

Method Summary

Methods inherited from RubyCachedThreadPool

#initialize

Methods inherited from RubyThreadPoolExecutor

#can_overflow?, #initialize, #length, #queue_length, #remaining_capacity, #status

Methods included from RubyExecutor

#<<, #kill, #post, #running?, #shutdown, #shutdown?, #shuttingdown?, #wait_for_termination

Methods included from Logging

#log

Methods included from Executor

#can_overflow?

Constructor Details

This class inherits a constructor from Concurrent::RubyCachedThreadPool