class Concurrent::JavaThreadPoolExecutor
@!macro thread_pool_executor
def completed_task_count
-
(Integer)- the completed_task_count
def completed_task_count @executor.getCompletedTaskCount end
def idletime
-
(Integer)- the idletime
def idletime @executor.getKeepAliveTime(java.util.concurrent.TimeUnit::SECONDS) end
def initialize(opts = {})
- See: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html -
Raises:
-
(ArgumentError)- if `:overflow_policy` is not one of the values specified -
(ArgumentError)- if `:min_threads` is less than zero -
(ArgumentError)- if `:max_threads` is less than one
Options Hash:
(**opts)-
:overflow_policy(Symbol) -- the policy for handling new -
:max_queue(Integer) -- the maximum -
:idletime(Integer) -- the maximum -
:min_threads(Integer) -- the minimum -
:max_threads(Integer) -- the maximum
Parameters:
-
opts(Hash) -- the options which configure the thread pool
def 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 @overflow_policy = opts.fetch(:overflow_policy, :abort) raise ArgumentError.new('max_threads must be greater than zero') if max_length <= 0 raise ArgumentError.new('min_threads cannot be less than zero') if min_length < 0 raise ArgumentError.new("#{@overflow_policy} is not a valid overflow policy") unless OVERFLOW_POLICIES.keys.include?(@overflow_policy) if min_length == 0 && @max_queue == 0 queue = java.util.concurrent.SynchronousQueue.new elsif @max_queue == 0 queue = java.util.concurrent.LinkedBlockingQueue.new 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, OVERFLOW_POLICIES[@overflow_policy].new) set_shutdown_hook end
def largest_length
-
(Integer)- the largest_length
def largest_length @executor.getLargestPoolSize end
def length
-
(Integer)- the length
def length @executor.getPoolSize end
def max_length
-
(Integer)- the max_length
def max_length @executor.getMaximumPoolSize end
def min_length
-
(Integer)- the min_length
def min_length @executor.getCorePoolSize end
def queue_length
-
(Integer)- the queue_length
def queue_length @executor.getQueue.size end
def remaining_capacity
-
(Integer)- the remaining_capacity
def remaining_capacity @max_queue == 0 ? -1 : @executor.getQueue.remainingCapacity end
def running?
-
(Boolean)- `true` when running, `false` when shutting down or shutdown
def running? super && ! @executor.isTerminating end
def scheduled_task_count
-
(Integer)- the scheduled_task_count
def scheduled_task_count @executor.getTaskCount end
def shutdown
but no new tasks will be accepted. Has no additional effect if the
Begin an orderly shutdown. Tasks already in the queue will be executed,
def shutdown super @executor.getQueue.clear nil end
def status
This method is supost to return the threads status, but Java API doesn't
This method is deprecated and will be removed soon.
def status warn '[DEPRECATED] `status` is deprecated and will be removed soon.' warn "Calls to `status` return an empty Array. Java ThreadPoolExecutor does not provide thread's status." [] end