Method: Concurrent::CachedThreadPool#initialize

Defined in:
lib/concurrent/cached_thread_pool.rb

#initialize(opts = {}) ⇒ CachedThreadPool

Returns a new instance of CachedThreadPool.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/concurrent/cached_thread_pool.rb', line 17

def initialize(opts = {})
  @idletime = (opts[:idletime] || DEFAULT_THREAD_IDLETIME).to_i
  raise ArgumentError.new('idletime must be greater than zero') if @idletime <= 0

  @max_threads = opts[:max_threads] || opts[:max] || MAX_POOL_SIZE
  if @max_threads < MIN_POOL_SIZE || @max_threads > MAX_POOL_SIZE
    raise ArgumentError.new("size must be from #{MIN_POOL_SIZE} to #{MAX_POOL_SIZE}")
  end

  @state = :running
  @pool = []
  @terminator = Event.new
  @mutex = Mutex.new

  @busy = []
  @idle = []
end