@@ -5,53 +5,28 @@ module Concurrent
55
66 # @!macro thread_pool_executor
77 # @!macro thread_pool_options
8- # @api private
8+ # @!visibility private
99 class JavaThreadPoolExecutor < JavaExecutorService
1010
11- # Default maximum number of threads that will be created in the pool.
11+ # @!macro thread_pool_executor_constant_default_max_pool_size
1212 DEFAULT_MAX_POOL_SIZE = java . lang . Integer ::MAX_VALUE # 2147483647
1313
14- # Default minimum number of threads that will be retained in the pool.
14+ # @!macro thread_pool_executor_constant_default_min_pool_size
1515 DEFAULT_MIN_POOL_SIZE = 0
1616
17- # Default maximum number of tasks that may be added to the task queue.
17+ # @!macro thread_pool_executor_constant_default_max_queue_size
1818 DEFAULT_MAX_QUEUE_SIZE = 0
1919
20- # Default maximum number of seconds a thread in the pool may remain idle
21- # before being reclaimed.
20+ # @!macro thread_pool_executor_constant_default_thread_timeout
2221 DEFAULT_THREAD_IDLETIMEOUT = 60
2322
24- # The maximum number of threads that may be created in the pool.
23+ # @!macro thread_pool_executor_attr_reader_max_length
2524 attr_reader :max_length
2625
27- # The maximum number of tasks that may be waiting in the work queue at any one time.
28- # When the queue size reaches `max_queue` subsequent tasks will be rejected in
29- # accordance with the configured `fallback_policy`.
26+ # @!macro thread_pool_executor_attr_reader_max_queue
3027 attr_reader :max_queue
3128
32- # Create a new thread pool.
33- #
34- # @param [Hash] opts the options which configure the thread pool
35- #
36- # @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
37- # number of threads to be created
38- # @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) the minimum
39- # number of threads to be retained
40- # @option opts [Integer] :idletime (DEFAULT_THREAD_IDLETIMEOUT) the maximum
41- # number of seconds a thread may be idle before being reclaimed
42- # @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
43- # number of tasks allowed in the work queue at any one time; a value of
44- # zero means the queue may grow without bound
45- # @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
46- # tasks that are received when the queue size has reached
47- # `max_queue` or the executir has shut down
48- #
49- # @raise [ArgumentError] if `:max_threads` is less than one
50- # @raise [ArgumentError] if `:min_threads` is less than zero
51- # @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
52- # in `FALLBACK_POLICIES`
53- #
54- # @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html
29+ # @!macro thread_pool_executor_method_initialize
5530 def initialize ( opts = { } )
5631 super ( opts )
5732 end
@@ -61,73 +36,52 @@ def can_overflow?
6136 @max_queue != 0
6237 end
6338
64- # The minimum number of threads that may be retained in the pool.
65- #
66- # @return [Integer] the min_length
39+ # @!macro thread_pool_executor_attr_reader_min_length
6740 def min_length
6841 @executor . getCorePoolSize
6942 end
7043
71- # The maximum number of threads that may be created in the pool.
72- #
73- # @return [Integer] the max_length
44+ # @!macro thread_pool_executor_attr_reader_max_length
7445 def max_length
7546 @executor . getMaximumPoolSize
7647 end
7748
78- # The number of threads currently in the pool.
79- #
80- # @return [Integer] the length
49+ # @!macro thread_pool_executor_attr_reader_length
8150 def length
8251 @executor . getPoolSize
8352 end
8453
85- # The largest number of threads that have been created in the pool since construction.
86- #
87- # @return [Integer] the largest_length
54+ # @!macro thread_pool_executor_attr_reader_largest_length
8855 def largest_length
8956 @executor . getLargestPoolSize
9057 end
9158
92- # The number of tasks that have been scheduled for execution on the pool since construction.
93- #
94- # @return [Integer] the scheduled_task_count
59+ # @!macro thread_pool_executor_attr_reader_scheduled_task_count
9560 def scheduled_task_count
9661 @executor . getTaskCount
9762 end
9863
99- # The number of tasks that have been completed by the pool since construction.
100- #
101- # @return [Integer] the completed_task_count
64+ # @!macro thread_pool_executor_attr_reader_completed_task_count
10265 def completed_task_count
10366 @executor . getCompletedTaskCount
10467 end
10568
106- # The number of seconds that a thread may be idle before being reclaimed.
107- #
108- # @return [Integer] the idletime
69+ # @!macro thread_pool_executor_attr_reader_idletime
10970 def idletime
11071 @executor . getKeepAliveTime ( java . util . concurrent . TimeUnit ::SECONDS )
11172 end
11273
113- # The number of tasks in the queue awaiting execution.
114- #
115- # @return [Integer] the queue_length
74+ # @!macro thread_pool_executor_attr_reader_queue_length
11675 def queue_length
11776 @executor . getQueue . size
11877 end
11978
120- # Number of tasks that may be enqueued before reaching `max_queue` and rejecting
121- # new tasks. A value of -1 indicates that the queue may grow without bound.
122- #
123- # @return [Integer] the remaining_capacity
79+ # @!macro thread_pool_executor_attr_reader_remaining_capacity
12480 def remaining_capacity
12581 @max_queue == 0 ? -1 : @executor . getQueue . remainingCapacity
12682 end
12783
128- # Is the thread pool running?
129- #
130- # @return [Boolean] `true` when running, `false` when shutting down or shutdown
84+ # @!macro executor_service_method_running_question
13185 def running?
13286 super && !@executor . isTerminating
13387 end
0 commit comments