@@ -5,53 +5,28 @@ module Concurrent
5
5
6
6
# @!macro thread_pool_executor
7
7
# @!macro thread_pool_options
8
- # @api private
8
+ # @!visibility private
9
9
class JavaThreadPoolExecutor < JavaExecutorService
10
10
11
- # Default maximum number of threads that will be created in the pool.
11
+ # @!macro thread_pool_executor_constant_default_max_pool_size
12
12
DEFAULT_MAX_POOL_SIZE = java . lang . Integer ::MAX_VALUE # 2147483647
13
13
14
- # Default minimum number of threads that will be retained in the pool.
14
+ # @!macro thread_pool_executor_constant_default_min_pool_size
15
15
DEFAULT_MIN_POOL_SIZE = 0
16
16
17
- # Default maximum number of tasks that may be added to the task queue.
17
+ # @!macro thread_pool_executor_constant_default_max_queue_size
18
18
DEFAULT_MAX_QUEUE_SIZE = 0
19
19
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
22
21
DEFAULT_THREAD_IDLETIMEOUT = 60
23
22
24
- # The maximum number of threads that may be created in the pool.
23
+ # @!macro thread_pool_executor_attr_reader_max_length
25
24
attr_reader :max_length
26
25
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
30
27
attr_reader :max_queue
31
28
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
55
30
def initialize ( opts = { } )
56
31
super ( opts )
57
32
end
@@ -61,73 +36,52 @@ def can_overflow?
61
36
@max_queue != 0
62
37
end
63
38
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
67
40
def min_length
68
41
@executor . getCorePoolSize
69
42
end
70
43
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
74
45
def max_length
75
46
@executor . getMaximumPoolSize
76
47
end
77
48
78
- # The number of threads currently in the pool.
79
- #
80
- # @return [Integer] the length
49
+ # @!macro thread_pool_executor_attr_reader_length
81
50
def length
82
51
@executor . getPoolSize
83
52
end
84
53
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
88
55
def largest_length
89
56
@executor . getLargestPoolSize
90
57
end
91
58
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
95
60
def scheduled_task_count
96
61
@executor . getTaskCount
97
62
end
98
63
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
102
65
def completed_task_count
103
66
@executor . getCompletedTaskCount
104
67
end
105
68
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
109
70
def idletime
110
71
@executor . getKeepAliveTime ( java . util . concurrent . TimeUnit ::SECONDS )
111
72
end
112
73
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
116
75
def queue_length
117
76
@executor . getQueue . size
118
77
end
119
78
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
124
80
def remaining_capacity
125
81
@max_queue == 0 ? -1 : @executor . getQueue . remainingCapacity
126
82
end
127
83
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
131
85
def running?
132
86
super && !@executor . isTerminating
133
87
end
0 commit comments