Skip to content

Commit f79b28b

Browse files
committed
Better documentation of Fixed and Cached thread pools.
1 parent 8a1f12c commit f79b28b

File tree

7 files changed

+185
-163
lines changed

7 files changed

+185
-163
lines changed

lib/concurrent/executor/cached_thread_pool.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ module Concurrent
3939
# @see Concurrent::JavaCachedThreadPool
4040
#
4141
# @!macro thread_pool_options
42+
#
43+
# @!macro thread_pool_executor_public_api
4244
class CachedThreadPool < CachedThreadPoolImplementation
45+
46+
# @!macro [new] cached_thread_pool_method_initialize
47+
#
48+
# Create a new thread pool.
49+
#
50+
# @param [Hash] opts the options defining pool behavior.
51+
# @option opts [Symbol] :fallback_policy (`:abort`) the fallback policy
52+
#
53+
# @raise [ArgumentError] if `fallback_policy` is not a known policy
54+
#
55+
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool--
56+
57+
# @!method initialize(opts = {})
58+
# @!macro cached_thread_pool_method_initialize
4359
end
4460
end

lib/concurrent/executor/fixed_thread_pool.rb

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,154 @@ module Concurrent
1414
end
1515
private_constant :FixedThreadPoolImplementation
1616

17+
# @!macro [new] thread_pool_executor_constant_default_max_pool_size
18+
# Default maximum number of threads that will be created in the pool.
19+
20+
# @!macro [new] thread_pool_executor_constant_default_min_pool_size
21+
# Default minimum number of threads that will be retained in the pool.
22+
23+
# @!macro [new] thread_pool_executor_constant_default_max_queue_size
24+
# Default maximum number of tasks that may be added to the task queue.
25+
26+
# @!macro [new] thread_pool_executor_constant_default_thread_timeout
27+
# Default maximum number of seconds a thread in the pool may remain idle
28+
# before being reclaimed.
29+
30+
# @!macro [new] thread_pool_executor_attr_reader_max_length
31+
# The maximum number of threads that may be created in the pool.
32+
# @return [Integer] The maximum number of threads that may be created in the pool.
33+
34+
# @!macro [new] thread_pool_executor_attr_reader_min_length
35+
# The minimum number of threads that may be retained in the pool.
36+
# @return [Integer] The minimum number of threads that may be retained in the pool.
37+
38+
# @!macro [new] thread_pool_executor_attr_reader_largest_length
39+
# The largest number of threads that have been created in the pool since construction.
40+
# @return [Integer] The largest number of threads that have been created in the pool since construction.
41+
42+
# @!macro [new] thread_pool_executor_attr_reader_scheduled_task_count
43+
# The number of tasks that have been scheduled for execution on the pool since construction.
44+
# @return [Integer] The number of tasks that have been scheduled for execution on the pool since construction.
45+
46+
# @!macro [new] thread_pool_executor_attr_reader_completed_task_count
47+
# The number of tasks that have been completed by the pool since construction.
48+
# @return [Integer] The number of tasks that have been completed by the pool since construction.
49+
50+
# @!macro [new] thread_pool_executor_attr_reader_idletime
51+
# The number of seconds that a thread may be idle before being reclaimed.
52+
# @return [Integer] The number of seconds that a thread may be idle before being reclaimed.
53+
54+
# @!macro [new] thread_pool_executor_attr_reader_max_queue
55+
# The maximum number of tasks that may be waiting in the work queue at any one time.
56+
# When the queue size reaches `max_queue` subsequent tasks will be rejected in
57+
# accordance with the configured `fallback_policy`.
58+
#
59+
# @return [Integer] The maximum number of tasks that may be waiting in the work queue at any one time.
60+
# When the queue size reaches `max_queue` subsequent tasks will be rejected in
61+
# accordance with the configured `fallback_policy`.
62+
63+
# @!macro [new] thread_pool_executor_attr_reader_length
64+
# The number of threads currently in the pool.
65+
# @return [Integer] The number of threads currently in the pool.
66+
67+
# @!macro [new] thread_pool_executor_attr_reader_queue_length
68+
# The number of tasks in the queue awaiting execution.
69+
# @return [Integer] The number of tasks in the queue awaiting execution.
70+
71+
# @!macro [new] thread_pool_executor_attr_reader_remaining_capacity
72+
# Number of tasks that may be enqueued before reaching `max_queue` and rejecting
73+
# new tasks. A value of -1 indicates that the queue may grow without bound.
74+
#
75+
# @return [Integer] Number of tasks that may be enqueued before reaching `max_queue` and rejecting
76+
# new tasks. A value of -1 indicates that the queue may grow without bound.
77+
78+
79+
80+
81+
82+
# @!macro [new] thread_pool_executor_public_api
83+
#
84+
# @!attribute [r] fallback_policy
85+
# @!macro executor_service_attr_reader_fallback_policy
86+
#
87+
# @!attribute [r] max_length
88+
# @!macro thread_pool_executor_attr_reader_max_length
89+
#
90+
# @!attribute [r] min_length
91+
# @!macro thread_pool_executor_attr_reader_min_length
92+
#
93+
# @!attribute [r] largest_length
94+
# @!macro thread_pool_executor_attr_reader_largest_length
95+
#
96+
# @!attribute [r] scheduled_task_count
97+
# @!macro thread_pool_executor_attr_reader_scheduled_task_count
98+
#
99+
# @!attribute [r] completed_task_count
100+
# @!macro thread_pool_executor_attr_reader_completed_task_count
101+
#
102+
# @!attribute [r] idletime
103+
# @!macro thread_pool_executor_attr_reader_idletime
104+
#
105+
# @!attribute [r] max_queue
106+
# @!macro thread_pool_executor_attr_reader_max_queue
107+
#
108+
# @!attribute [r] length
109+
# @!macro thread_pool_executor_attr_reader_length
110+
#
111+
# @!attribute [r] queue_length
112+
# @!macro thread_pool_executor_attr_reader_queue_length
113+
#
114+
# @!attribute [r] remaining_capacity
115+
# @!macro thread_pool_executor_attr_reader_remaining_capacity
116+
#
117+
# @!method can_overflow?
118+
# @!macro executor_service_method_can_overflow_question
119+
#
120+
# @!method shutdown
121+
# @!macro executor_service_method_shutdown
122+
#
123+
# @!method kill
124+
# @!macro executor_service_method_kill
125+
#
126+
# @!method wait_for_termination(timeout = nil)
127+
# @!macro executor_service_method_wait_for_termination
128+
#
129+
# @!method running?
130+
# @!macro executor_service_method_running_question
131+
#
132+
# @!method shuttingdown?
133+
# @!macro executor_service_method_shuttingdown_question
134+
#
135+
# @!method shutdown?
136+
# @!macro executor_service_method_shutdown_question
137+
#
138+
# @!method auto_terminate?
139+
# @!macro executor_service_method_auto_terminate_question
140+
#
141+
# @!method auto_terminate=(value)
142+
# @!macro executor_service_method_auto_terminate_setter
143+
144+
145+
146+
147+
148+
# @!macro [new] fixed_thread_pool_method_initialize
149+
#
150+
# Create a new thread pool.
151+
#
152+
# @param [Integer] num_threads the number of threads to allocate
153+
# @param [Hash] opts the options defining pool behavior.
154+
# @option opts [Symbol] :fallback_policy (`:abort`) the fallback policy
155+
#
156+
# @raise [ArgumentError] if `num_threads` is less than or equal to zero
157+
# @raise [ArgumentError] if `fallback_policy` is not a known policy
158+
#
159+
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool-int-
160+
161+
162+
163+
164+
17165
# @!macro [attach] fixed_thread_pool
18166
#
19167
# A thread pool with a set number of threads. The number of threads in the pool
@@ -26,6 +174,8 @@ module Concurrent
26174
#
27175
# @!macro [attach] thread_pool_options
28176
#
177+
# **Thread Pool Options**
178+
#
29179
# Thread pools support several configuration options:
30180
#
31181
# * `idletime`: The number of seconds that a thread may be idle before being reclaimed.
@@ -78,6 +228,11 @@ module Concurrent
78228
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html Java Executors class
79229
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html Java ExecutorService interface
80230
# @see http://ruby-doc.org//core-2.2.0/Kernel.html#method-i-at_exit Kernel#at_exit
231+
#
232+
# @!macro thread_pool_executor_public_api
81233
class FixedThreadPool < FixedThreadPoolImplementation
234+
235+
# @!method initialize(num_threads, opts = {})
236+
# @!macro fixed_thread_pool_method_initialize
82237
end
83238
end

lib/concurrent/executor/java_cached_thread_pool.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@ module Concurrent
66

77
# @!macro cached_thread_pool
88
# @!macro thread_pool_options
9-
# @api private
9+
# @!macro thread_pool_executor_public_api
10+
# @!visibility private
1011
class JavaCachedThreadPool < JavaThreadPoolExecutor
1112

12-
# Create a new thread pool.
13-
#
14-
# @param [Hash] opts the options defining pool behavior.
15-
# @option opts [Symbol] :fallback_policy (`:abort`) the fallback policy
16-
#
17-
# @raise [ArgumentError] if `fallback_policy` is not a known policy
18-
#
19-
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool--
13+
# @!macro cached_thread_pool_method_initialize
2014
def initialize(opts = {})
2115
defaults = { idletime: DEFAULT_THREAD_IDLETIMEOUT }
2216
overrides = { min_threads: 0,

lib/concurrent/executor/java_fixed_thread_pool.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ module Concurrent
66

77
# @!macro fixed_thread_pool
88
# @!macro thread_pool_options
9-
# @api private
9+
# @!macro thread_pool_executor_public_api
10+
# @!visibility private
1011
class JavaFixedThreadPool < JavaThreadPoolExecutor
1112

12-
# Create a new thread pool.
13-
#
14-
# @param [Hash] opts the options defining pool behavior.
15-
# @option opts [Symbol] :fallback_policy (`:abort`) the fallback policy
16-
#
17-
# @raise [ArgumentError] if `num_threads` is less than or equal to zero
18-
# @raise [ArgumentError] if `fallback_policy` is not a known policy
19-
#
20-
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool-int-
13+
# @!macro fixed_thread_pool_method_initialize
2114
def initialize(num_threads, opts = {})
2215
raise ArgumentError.new('number of threads must be greater than zero') if num_threads.to_i < 1
2316
defaults = { max_queue: DEFAULT_MAX_QUEUE_SIZE,

lib/concurrent/executor/ruby_cached_thread_pool.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ module Concurrent
44

55
# @!macro cached_thread_pool
66
# @!macro thread_pool_options
7-
# @api private
7+
# @!macro thread_pool_executor_public_api
8+
# @!visibility private
89
class RubyCachedThreadPool < RubyThreadPoolExecutor
910

10-
# Create a new thread pool.
11-
#
12-
# @param [Hash] opts the options defining pool behavior.
13-
# @option opts [Symbol] :fallback_policy (`:abort`) the fallback policy
14-
#
15-
# @raise [ArgumentError] if `fallback_policy` is not a known policy
11+
# @!macro cached_thread_pool_method_initialize
1612
def initialize(opts = {})
1713
defaults = { idletime: DEFAULT_THREAD_IDLETIMEOUT }
1814
overrides = { min_threads: 0,

lib/concurrent/executor/ruby_fixed_thread_pool.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@ module Concurrent
44

55
# @!macro fixed_thread_pool
66
# @!macro thread_pool_options
7-
# @api private
7+
# @!macro thread_pool_executor_public_api
8+
# @!visibility private
89
class RubyFixedThreadPool < RubyThreadPoolExecutor
910

10-
# Create a new thread pool.
11-
#
12-
# @param [Integer] num_threads the number of threads to allocate
13-
# @param [Hash] opts the options defining pool behavior.
14-
# @option opts [Symbol] :fallback_policy (`:abort`) the fallback policy
15-
#
16-
# @raise [ArgumentError] if `num_threads` is less than or equal to zero
17-
# @raise [ArgumentError] if `fallback_policy` is not a known policy
11+
# @!macro fixed_thread_pool_method_initialize
1812
def initialize(num_threads, opts = {})
1913
raise ArgumentError.new('number of threads must be greater than zero') if num_threads.to_i < 1
2014
defaults = { max_queue: DEFAULT_MAX_QUEUE_SIZE,

0 commit comments

Comments
 (0)