class Concurrent::JavaThreadPoolExecutor

@!macro thread_pool_executor @!macro thread_pool_options @!visibility private

Constants

DEFAULT_MAX_POOL_SIZE

@!macro thread_pool_executor_constant_default_max_pool_size

DEFAULT_MAX_QUEUE_SIZE

@!macro thread_pool_executor_constant_default_max_queue_size

DEFAULT_MIN_POOL_SIZE

@!macro thread_pool_executor_constant_default_min_pool_size

DEFAULT_SYNCHRONOUS

@!macro thread_pool_executor_constant_default_synchronous

DEFAULT_THREAD_IDLETIMEOUT

@!macro thread_pool_executor_constant_default_thread_timeout

Attributes

max_length[R]

@!macro thread_pool_executor_attr_reader_max_length

max_queue[R]

@!macro thread_pool_executor_attr_reader_max_queue

synchronous[R]

@!macro thread_pool_executor_attr_reader_synchronous

Public Class Methods

new(opts = {}) click to toggle source

@!macro thread_pool_executor_method_initialize

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 37
def initialize(opts = {})
  super(opts)
end

Public Instance Methods

can_overflow?() click to toggle source

@!macro executor_service_method_can_overflow_question

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 42
def can_overflow?
  @max_queue != 0
end
completed_task_count() click to toggle source

@!macro thread_pool_executor_attr_reader_completed_task_count

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 72
def completed_task_count
  @executor.getCompletedTaskCount
end
idletime() click to toggle source

@!macro thread_pool_executor_attr_reader_idletime

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 77
def idletime
  @executor.getKeepAliveTime(java.util.concurrent.TimeUnit::SECONDS)
end
largest_length() click to toggle source

@!macro thread_pool_executor_attr_reader_largest_length

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 62
def largest_length
  @executor.getLargestPoolSize
end
length() click to toggle source

@!macro thread_pool_executor_attr_reader_length

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 57
def length
  @executor.getPoolSize
end
min_length() click to toggle source

@!macro thread_pool_executor_attr_reader_min_length

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 47
def min_length
  @executor.getCorePoolSize
end
prune_pool() click to toggle source

@!macro thread_pool_executor_method_prune_pool

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 97
def prune_pool
end
queue_length() click to toggle source

@!macro thread_pool_executor_attr_reader_queue_length

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 82
def queue_length
  @executor.getQueue.size
end
remaining_capacity() click to toggle source

@!macro thread_pool_executor_attr_reader_remaining_capacity

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 87
def remaining_capacity
  @max_queue == 0 ? -1 : @executor.getQueue.remainingCapacity
end
running?() click to toggle source

@!macro executor_service_method_running_question

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 92
def running?
  super && !@executor.isTerminating
end
scheduled_task_count() click to toggle source

@!macro thread_pool_executor_attr_reader_scheduled_task_count

# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 67
def scheduled_task_count
  @executor.getTaskCount
end

Private Instance Methods

ns_initialize(opts) click to toggle source
# File lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb, line 102
def ns_initialize(opts)
  min_length       = opts.fetch(:min_threads, DEFAULT_MIN_POOL_SIZE).to_i
  max_length       = opts.fetch(:max_threads, DEFAULT_MAX_POOL_SIZE).to_i
  idletime         = opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT).to_i
  @max_queue       = opts.fetch(:max_queue, DEFAULT_MAX_QUEUE_SIZE).to_i
  @synchronous     = opts.fetch(:synchronous, DEFAULT_SYNCHRONOUS)
  @fallback_policy = opts.fetch(:fallback_policy, :abort)

  raise ArgumentError.new("`synchronous` cannot be set unless `max_queue` is 0") if @synchronous && @max_queue > 0
  raise ArgumentError.new("`max_threads` cannot be less than #{DEFAULT_MIN_POOL_SIZE}") if max_length < DEFAULT_MIN_POOL_SIZE
  raise ArgumentError.new("`max_threads` cannot be greater than #{DEFAULT_MAX_POOL_SIZE}") if max_length > DEFAULT_MAX_POOL_SIZE
  raise ArgumentError.new("`min_threads` cannot be less than #{DEFAULT_MIN_POOL_SIZE}") if min_length < DEFAULT_MIN_POOL_SIZE
  raise ArgumentError.new("`min_threads` cannot be more than `max_threads`") if min_length > max_length
  raise ArgumentError.new("#{fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.include?(@fallback_policy)

  if @max_queue == 0
    if @synchronous
      queue = java.util.concurrent.SynchronousQueue.new
    else
      queue = java.util.concurrent.LinkedBlockingQueue.new
    end
  else
    queue = java.util.concurrent.LinkedBlockingQueue.new(@max_queue)
  end

  @executor = java.util.concurrent.ThreadPoolExecutor.new(
      min_length,
      max_length,
      idletime,
      java.util.concurrent.TimeUnit::SECONDS,
      queue,
      DaemonThreadFactory.new(ns_auto_terminate?),
      FALLBACK_POLICY_CLASSES[@fallback_policy].new)

end