concurrent-ruby 1.0.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +115 -0
- data/Gemfile +42 -0
- data/{LICENSE.txt → LICENSE.md} +2 -0
- data/README.md +242 -105
- data/Rakefile +332 -0
- data/ext/concurrent-ruby/ConcurrentRubyService.java +17 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/AtomicReferenceLibrary.java +175 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JRubyMapBackendLibrary.java +248 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaAtomicBooleanLibrary.java +93 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java +113 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaSemaphoreLibrary.java +159 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/SynchronizationLibrary.java +307 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/ConcurrentHashMap.java +31 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/ConcurrentHashMapV8.java +3863 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/LongAdder.java +203 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/Striped64.java +342 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/nounsafe/ConcurrentHashMapV8.java +3800 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/nounsafe/LongAdder.java +204 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/nounsafe/Striped64.java +291 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166y/ThreadLocalRandom.java +199 -0
- data/lib/concurrent-ruby/concurrent-ruby.rb +1 -0
- data/lib/{concurrent.rb → concurrent-ruby/concurrent.rb} +24 -20
- data/lib/{concurrent → concurrent-ruby/concurrent}/agent.rb +7 -7
- data/lib/concurrent-ruby/concurrent/array.rb +66 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/async.rb +18 -4
- data/lib/{concurrent → concurrent-ruby/concurrent}/atom.rb +10 -10
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/abstract_thread_local_var.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/atomic_boolean.rb +26 -22
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/atomic_fixnum.rb +27 -23
- data/lib/concurrent-ruby/concurrent/atomic/atomic_markable_reference.rb +164 -0
- data/lib/concurrent-ruby/concurrent/atomic/atomic_reference.rb +204 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/count_down_latch.rb +7 -7
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/cyclic_barrier.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/event.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/java_count_down_latch.rb +9 -6
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/java_thread_local_var.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/mutex_atomic_boolean.rb +2 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/mutex_atomic_fixnum.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/mutex_count_down_latch.rb +1 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/mutex_semaphore.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/read_write_lock.rb +2 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/reentrant_read_write_lock.rb +3 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/ruby_thread_local_var.rb +43 -33
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/semaphore.rb +8 -8
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic/thread_local_var.rb +8 -8
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic_reference/mutex_atomic.rb +3 -8
- data/lib/{concurrent → concurrent-ruby/concurrent}/atomic_reference/numeric_cas_wrapper.rb +1 -1
- data/lib/concurrent-ruby/concurrent/atomics.rb +10 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/copy_on_notify_observer_set.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/copy_on_write_observer_set.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/java_non_concurrent_priority_queue.rb +0 -0
- data/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb +158 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/atomic_reference_map_backend.rb +3 -3
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/mri_map_backend.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/non_concurrent_map_backend.rb +1 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/map/synchronized_map_backend.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/non_concurrent_priority_queue.rb +30 -30
- data/lib/{concurrent → concurrent-ruby/concurrent}/collection/ruby_non_concurrent_priority_queue.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/concern/deprecation.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/concern/dereferenceable.rb +3 -3
- data/lib/{concurrent → concurrent-ruby/concurrent}/concern/logging.rb +6 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/concern/obligation.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/concern/observable.rb +7 -7
- data/lib/concurrent-ruby/concurrent/concurrent_ruby.jar +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/configuration.rb +15 -15
- data/lib/{concurrent → concurrent-ruby/concurrent}/constants.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/dataflow.rb +2 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/delay.rb +9 -7
- data/lib/{concurrent → concurrent-ruby/concurrent}/errors.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/exchanger.rb +21 -25
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/abstract_executor_service.rb +19 -25
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/cached_thread_pool.rb +5 -5
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/executor_service.rb +17 -17
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/fixed_thread_pool.rb +27 -30
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/immediate_executor.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/indirect_immediate_executor.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/java_executor_service.rb +19 -16
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/java_single_thread_executor.rb +4 -3
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/java_thread_pool_executor.rb +12 -8
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/ruby_executor_service.rb +0 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/ruby_single_thread_executor.rb +0 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/ruby_thread_pool_executor.rb +9 -4
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/safe_task_executor.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/serial_executor_service.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/serialized_execution.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/serialized_execution_delegator.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/simple_executor_service.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/single_thread_executor.rb +3 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/thread_pool_executor.rb +6 -6
- data/lib/{concurrent → concurrent-ruby/concurrent}/executor/timer_set.rb +14 -17
- data/lib/{concurrent → concurrent-ruby/concurrent}/executors.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/future.rb +4 -1
- data/lib/concurrent-ruby/concurrent/hash.rb +59 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/immutable_struct.rb +8 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/ivar.rb +5 -6
- data/lib/concurrent-ruby/concurrent/map.rb +337 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/maybe.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/mutable_struct.rb +25 -14
- data/lib/{concurrent → concurrent-ruby/concurrent}/mvar.rb +2 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/options.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/promise.rb +53 -21
- data/lib/concurrent-ruby/concurrent/promises.rb +2167 -0
- data/lib/concurrent-ruby/concurrent/re_include.rb +58 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/scheduled_task.rb +0 -0
- data/lib/concurrent-ruby/concurrent/set.rb +66 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/settable_struct.rb +11 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization.rb +4 -5
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/abstract_lockable_object.rb +5 -5
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/abstract_object.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/abstract_struct.rb +18 -4
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/condition.rb +2 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/jruby_lockable_object.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/jruby_object.rb +1 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/lock.rb +2 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/lockable_object.rb +6 -6
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/mri_object.rb +1 -0
- data/lib/{concurrent/synchronization/mri_lockable_object.rb → concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb} +19 -14
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/object.rb +53 -23
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/rbx_lockable_object.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/rbx_object.rb +1 -0
- data/lib/concurrent-ruby/concurrent/synchronization/truffleruby_object.rb +47 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/synchronization/volatile.rb +11 -9
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/synchronized_delegator.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/adder.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/cheap_lockable.rb +0 -0
- data/lib/concurrent-ruby/concurrent/thread_safe/util/data_structures.rb +63 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/power_of_two_tuple.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/striped64.rb +9 -4
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/volatile.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/thread_safe/util/xor_shift_random.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/timer_task.rb +5 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/tuple.rb +1 -1
- data/lib/{concurrent → concurrent-ruby/concurrent}/tvar.rb +2 -2
- data/lib/{concurrent → concurrent-ruby/concurrent}/utility/engine.rb +4 -4
- data/lib/{concurrent → concurrent-ruby/concurrent}/utility/monotonic_time.rb +3 -3
- data/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb +79 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/utility/native_integer.rb +0 -0
- data/lib/{concurrent → concurrent-ruby/concurrent}/utility/processor_counter.rb +5 -2
- data/lib/concurrent-ruby/concurrent/version.rb +3 -0
- metadata +146 -131
- data/lib/concurrent/array.rb +0 -39
- data/lib/concurrent/atomic/atomic_reference.rb +0 -51
- data/lib/concurrent/atomic_reference/concurrent_update_error.rb +0 -8
- data/lib/concurrent/atomic_reference/direct_update.rb +0 -81
- data/lib/concurrent/atomic_reference/jruby+truffle.rb +0 -2
- data/lib/concurrent/atomic_reference/jruby.rb +0 -16
- data/lib/concurrent/atomic_reference/rbx.rb +0 -22
- data/lib/concurrent/atomic_reference/ruby.rb +0 -32
- data/lib/concurrent/atomics.rb +0 -53
- data/lib/concurrent/edge.rb +0 -26
- data/lib/concurrent/hash.rb +0 -36
- data/lib/concurrent/lazy_register.rb +0 -81
- data/lib/concurrent/map.rb +0 -240
- data/lib/concurrent/synchronization/truffle_lockable_object.rb +0 -9
- data/lib/concurrent/synchronization/truffle_object.rb +0 -31
- data/lib/concurrent/thread_safe/util/array_hash_rbx.rb +0 -30
- data/lib/concurrent/utility/at_exit.rb +0 -97
- data/lib/concurrent/utility/native_extension_loader.rb +0 -73
- data/lib/concurrent/version.rb +0 -4
@@ -26,7 +26,7 @@ module Concurrent
|
|
26
26
|
# @!macro thread_pool_options
|
27
27
|
class CachedThreadPool < ThreadPoolExecutor
|
28
28
|
|
29
|
-
# @!macro
|
29
|
+
# @!macro cached_thread_pool_method_initialize
|
30
30
|
#
|
31
31
|
# Create a new thread pool.
|
32
32
|
#
|
@@ -37,7 +37,7 @@ module Concurrent
|
|
37
37
|
#
|
38
38
|
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool--
|
39
39
|
def initialize(opts = {})
|
40
|
-
defaults = { idletime:
|
40
|
+
defaults = { idletime: DEFAULT_THREAD_IDLETIMEOUT }
|
41
41
|
overrides = { min_threads: 0,
|
42
42
|
max_threads: DEFAULT_MAX_POOL_SIZE,
|
43
43
|
max_queue: DEFAULT_MAX_QUEUE_SIZE }
|
@@ -51,11 +51,11 @@ module Concurrent
|
|
51
51
|
def ns_initialize(opts)
|
52
52
|
super(opts)
|
53
53
|
if Concurrent.on_jruby?
|
54
|
-
@max_queue
|
55
|
-
@executor
|
54
|
+
@max_queue = 0
|
55
|
+
@executor = java.util.concurrent.Executors.newCachedThreadPool(
|
56
|
+
DaemonThreadFactory.new(ns_auto_terminate?))
|
56
57
|
@executor.setRejectedExecutionHandler(FALLBACK_POLICY_CLASSES[@fallback_policy].new)
|
57
58
|
@executor.setKeepAliveTime(opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT), java.util.concurrent.TimeUnit::SECONDS)
|
58
|
-
self.auto_terminate = opts.fetch(:auto_terminate, true)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -4,7 +4,7 @@ module Concurrent
|
|
4
4
|
|
5
5
|
###################################################################
|
6
6
|
|
7
|
-
# @!macro
|
7
|
+
# @!macro executor_service_method_post
|
8
8
|
#
|
9
9
|
# Submit a task to the executor for asynchronous processing.
|
10
10
|
#
|
@@ -17,7 +17,7 @@ module Concurrent
|
|
17
17
|
#
|
18
18
|
# @raise [ArgumentError] if no task is given
|
19
19
|
|
20
|
-
# @!macro
|
20
|
+
# @!macro executor_service_method_left_shift
|
21
21
|
#
|
22
22
|
# Submit a task to the executor for asynchronous processing.
|
23
23
|
#
|
@@ -25,13 +25,13 @@ module Concurrent
|
|
25
25
|
#
|
26
26
|
# @return [self] returns itself
|
27
27
|
|
28
|
-
# @!macro
|
28
|
+
# @!macro executor_service_method_can_overflow_question
|
29
29
|
#
|
30
30
|
# Does the task queue have a maximum size?
|
31
31
|
#
|
32
32
|
# @return [Boolean] True if the task queue has a maximum size else false.
|
33
33
|
|
34
|
-
# @!macro
|
34
|
+
# @!macro executor_service_method_serialized_question
|
35
35
|
#
|
36
36
|
# Does this executor guarantee serialization of its operations?
|
37
37
|
#
|
@@ -41,7 +41,7 @@ module Concurrent
|
|
41
41
|
|
42
42
|
###################################################################
|
43
43
|
|
44
|
-
# @!macro
|
44
|
+
# @!macro executor_service_public_api
|
45
45
|
#
|
46
46
|
# @!method post(*args, &task)
|
47
47
|
# @!macro executor_service_method_post
|
@@ -57,23 +57,23 @@ module Concurrent
|
|
57
57
|
|
58
58
|
###################################################################
|
59
59
|
|
60
|
-
# @!macro
|
60
|
+
# @!macro executor_service_attr_reader_fallback_policy
|
61
61
|
# @return [Symbol] The fallback policy in effect. Either `:abort`, `:discard`, or `:caller_runs`.
|
62
62
|
|
63
|
-
# @!macro
|
63
|
+
# @!macro executor_service_method_shutdown
|
64
64
|
#
|
65
65
|
# Begin an orderly shutdown. Tasks already in the queue will be executed,
|
66
66
|
# but no new tasks will be accepted. Has no additional effect if the
|
67
67
|
# thread pool is not running.
|
68
68
|
|
69
|
-
# @!macro
|
69
|
+
# @!macro executor_service_method_kill
|
70
70
|
#
|
71
71
|
# Begin an immediate shutdown. In-progress tasks will be allowed to
|
72
72
|
# complete but enqueued tasks will be dismissed and no new tasks
|
73
73
|
# will be accepted. Has no additional effect if the thread pool is
|
74
74
|
# not running.
|
75
75
|
|
76
|
-
# @!macro
|
76
|
+
# @!macro executor_service_method_wait_for_termination
|
77
77
|
#
|
78
78
|
# Block until executor shutdown is complete or until `timeout` seconds have
|
79
79
|
# passed.
|
@@ -85,41 +85,41 @@ module Concurrent
|
|
85
85
|
#
|
86
86
|
# @return [Boolean] `true` if shutdown complete or false on `timeout`
|
87
87
|
|
88
|
-
# @!macro
|
88
|
+
# @!macro executor_service_method_running_question
|
89
89
|
#
|
90
90
|
# Is the executor running?
|
91
91
|
#
|
92
92
|
# @return [Boolean] `true` when running, `false` when shutting down or shutdown
|
93
93
|
|
94
|
-
# @!macro
|
94
|
+
# @!macro executor_service_method_shuttingdown_question
|
95
95
|
#
|
96
96
|
# Is the executor shuttingdown?
|
97
97
|
#
|
98
98
|
# @return [Boolean] `true` when not running and not shutdown, else `false`
|
99
99
|
|
100
|
-
# @!macro
|
100
|
+
# @!macro executor_service_method_shutdown_question
|
101
101
|
#
|
102
102
|
# Is the executor shutdown?
|
103
103
|
#
|
104
104
|
# @return [Boolean] `true` when shutdown, `false` when shutting down or running
|
105
105
|
|
106
|
-
# @!macro
|
106
|
+
# @!macro executor_service_method_auto_terminate_question
|
107
107
|
#
|
108
108
|
# Is the executor auto-terminate when the application exits?
|
109
109
|
#
|
110
110
|
# @return [Boolean] `true` when auto-termination is enabled else `false`.
|
111
111
|
|
112
|
-
# @!macro
|
112
|
+
# @!macro executor_service_method_auto_terminate_setter
|
113
113
|
#
|
114
|
-
# Set the auto-terminate behavior for this executor.
|
115
114
|
#
|
115
|
+
# Set the auto-terminate behavior for this executor.
|
116
|
+
# @deprecated Has no effect
|
116
117
|
# @param [Boolean] value The new auto-terminate value to set for this executor.
|
117
|
-
#
|
118
118
|
# @return [Boolean] `true` when auto-termination is enabled else `false`.
|
119
119
|
|
120
120
|
###################################################################
|
121
121
|
|
122
|
-
# @!macro
|
122
|
+
# @!macro abstract_executor_service_public_api
|
123
123
|
#
|
124
124
|
# @!macro executor_service_public_api
|
125
125
|
#
|
@@ -3,44 +3,44 @@ require 'concurrent/executor/thread_pool_executor'
|
|
3
3
|
|
4
4
|
module Concurrent
|
5
5
|
|
6
|
-
# @!macro
|
6
|
+
# @!macro thread_pool_executor_constant_default_max_pool_size
|
7
7
|
# Default maximum number of threads that will be created in the pool.
|
8
8
|
|
9
|
-
# @!macro
|
9
|
+
# @!macro thread_pool_executor_constant_default_min_pool_size
|
10
10
|
# Default minimum number of threads that will be retained in the pool.
|
11
11
|
|
12
|
-
# @!macro
|
12
|
+
# @!macro thread_pool_executor_constant_default_max_queue_size
|
13
13
|
# Default maximum number of tasks that may be added to the task queue.
|
14
14
|
|
15
|
-
# @!macro
|
15
|
+
# @!macro thread_pool_executor_constant_default_thread_timeout
|
16
16
|
# Default maximum number of seconds a thread in the pool may remain idle
|
17
17
|
# before being reclaimed.
|
18
18
|
|
19
|
-
# @!macro
|
19
|
+
# @!macro thread_pool_executor_attr_reader_max_length
|
20
20
|
# The maximum number of threads that may be created in the pool.
|
21
21
|
# @return [Integer] The maximum number of threads that may be created in the pool.
|
22
22
|
|
23
|
-
# @!macro
|
23
|
+
# @!macro thread_pool_executor_attr_reader_min_length
|
24
24
|
# The minimum number of threads that may be retained in the pool.
|
25
25
|
# @return [Integer] The minimum number of threads that may be retained in the pool.
|
26
26
|
|
27
|
-
# @!macro
|
27
|
+
# @!macro thread_pool_executor_attr_reader_largest_length
|
28
28
|
# The largest number of threads that have been created in the pool since construction.
|
29
29
|
# @return [Integer] The largest number of threads that have been created in the pool since construction.
|
30
30
|
|
31
|
-
# @!macro
|
31
|
+
# @!macro thread_pool_executor_attr_reader_scheduled_task_count
|
32
32
|
# The number of tasks that have been scheduled for execution on the pool since construction.
|
33
33
|
# @return [Integer] The number of tasks that have been scheduled for execution on the pool since construction.
|
34
34
|
|
35
|
-
# @!macro
|
35
|
+
# @!macro thread_pool_executor_attr_reader_completed_task_count
|
36
36
|
# The number of tasks that have been completed by the pool since construction.
|
37
37
|
# @return [Integer] The number of tasks that have been completed by the pool since construction.
|
38
38
|
|
39
|
-
# @!macro
|
39
|
+
# @!macro thread_pool_executor_attr_reader_idletime
|
40
40
|
# The number of seconds that a thread may be idle before being reclaimed.
|
41
41
|
# @return [Integer] The number of seconds that a thread may be idle before being reclaimed.
|
42
42
|
|
43
|
-
# @!macro
|
43
|
+
# @!macro thread_pool_executor_attr_reader_max_queue
|
44
44
|
# The maximum number of tasks that may be waiting in the work queue at any one time.
|
45
45
|
# When the queue size reaches `max_queue` subsequent tasks will be rejected in
|
46
46
|
# accordance with the configured `fallback_policy`.
|
@@ -49,15 +49,15 @@ module Concurrent
|
|
49
49
|
# When the queue size reaches `max_queue` subsequent tasks will be rejected in
|
50
50
|
# accordance with the configured `fallback_policy`.
|
51
51
|
|
52
|
-
# @!macro
|
52
|
+
# @!macro thread_pool_executor_attr_reader_length
|
53
53
|
# The number of threads currently in the pool.
|
54
54
|
# @return [Integer] The number of threads currently in the pool.
|
55
55
|
|
56
|
-
# @!macro
|
56
|
+
# @!macro thread_pool_executor_attr_reader_queue_length
|
57
57
|
# The number of tasks in the queue awaiting execution.
|
58
58
|
# @return [Integer] The number of tasks in the queue awaiting execution.
|
59
59
|
|
60
|
-
# @!macro
|
60
|
+
# @!macro thread_pool_executor_attr_reader_remaining_capacity
|
61
61
|
# Number of tasks that may be enqueued before reaching `max_queue` and rejecting
|
62
62
|
# new tasks. A value of -1 indicates that the queue may grow without bound.
|
63
63
|
#
|
@@ -68,7 +68,7 @@ module Concurrent
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
# @!macro
|
71
|
+
# @!macro thread_pool_executor_public_api
|
72
72
|
#
|
73
73
|
# @!macro abstract_executor_service_public_api
|
74
74
|
#
|
@@ -108,19 +108,20 @@ module Concurrent
|
|
108
108
|
|
109
109
|
|
110
110
|
|
111
|
-
# @!macro
|
111
|
+
# @!macro thread_pool_options
|
112
112
|
#
|
113
113
|
# **Thread Pool Options**
|
114
114
|
#
|
115
115
|
# Thread pools support several configuration options:
|
116
116
|
#
|
117
117
|
# * `idletime`: The number of seconds that a thread may be idle before being reclaimed.
|
118
|
+
# * `name`: The name of the executor (optional). Printed in the executor's `#to_s` output and
|
119
|
+
# a `<name>-worker-<id>` name is given to its threads if supported by used Ruby
|
120
|
+
# implementation. `<id>` is uniq for each thread.
|
118
121
|
# * `max_queue`: The maximum number of tasks that may be waiting in the work queue at
|
119
122
|
# any one time. When the queue size reaches `max_queue` and no new threads can be created,
|
120
123
|
# subsequent tasks will be rejected in accordance with the configured `fallback_policy`.
|
121
|
-
# * `auto_terminate`: When true (default)
|
122
|
-
# will stop the thread pool when the application exits. See below for more information
|
123
|
-
# on shutting down thread pools.
|
124
|
+
# * `auto_terminate`: When true (default), the threads started will be marked as daemon.
|
124
125
|
# * `fallback_policy`: The policy defining how rejected tasks are handled.
|
125
126
|
#
|
126
127
|
# Three fallback policies are supported:
|
@@ -145,16 +146,12 @@ module Concurrent
|
|
145
146
|
#
|
146
147
|
# On some runtime platforms (most notably the JVM) the application will not
|
147
148
|
# exit until all thread pools have been shutdown. To prevent applications from
|
148
|
-
# "hanging" on exit all
|
149
|
-
#
|
150
|
-
# force method to stop the pool and makes no guarantees regarding resources being
|
151
|
-
# used by any tasks still running. Registration of this `at_exit` handler can be
|
152
|
-
# prevented by setting the thread pool's constructor `:auto_terminate` option to
|
153
|
-
# `false` when the thread pool is created. All thread pools support this option.
|
149
|
+
# "hanging" on exit, all threads can be marked as daemon according to the
|
150
|
+
# `:auto_terminate` option.
|
154
151
|
#
|
155
152
|
# ```ruby
|
156
|
-
# pool1 = Concurrent::FixedThreadPool.new(5) #
|
157
|
-
# pool2 = Concurrent::FixedThreadPool.new(5, auto_terminate: false) #
|
153
|
+
# pool1 = Concurrent::FixedThreadPool.new(5) # threads will be marked as daemon
|
154
|
+
# pool2 = Concurrent::FixedThreadPool.new(5, auto_terminate: false) # mark threads as non-daemon
|
158
155
|
# ```
|
159
156
|
#
|
160
157
|
# @note Failure to properly shutdown a thread pool can lead to unpredictable results.
|
@@ -163,13 +160,13 @@ module Concurrent
|
|
163
160
|
# @see http://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html Java Tutorials: Thread Pools
|
164
161
|
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html Java Executors class
|
165
162
|
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html Java ExecutorService interface
|
166
|
-
# @see
|
163
|
+
# @see https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#setDaemon-boolean-
|
167
164
|
|
168
165
|
|
169
166
|
|
170
167
|
|
171
168
|
|
172
|
-
# @!macro
|
169
|
+
# @!macro fixed_thread_pool
|
173
170
|
#
|
174
171
|
# A thread pool that reuses a fixed number of threads operating off an unbounded queue.
|
175
172
|
# At any point, at most `num_threads` will be active processing tasks. When all threads are busy new
|
@@ -182,7 +179,7 @@ module Concurrent
|
|
182
179
|
# @!macro thread_pool_options
|
183
180
|
class FixedThreadPool < ThreadPoolExecutor
|
184
181
|
|
185
|
-
# @!macro
|
182
|
+
# @!macro fixed_thread_pool_method_initialize
|
186
183
|
#
|
187
184
|
# Create a new thread pool.
|
188
185
|
#
|
File without changes
|
File without changes
|
@@ -18,15 +18,10 @@ if Concurrent.on_jruby?
|
|
18
18
|
}.freeze
|
19
19
|
private_constant :FALLBACK_POLICY_CLASSES
|
20
20
|
|
21
|
-
def initialize(*args, &block)
|
22
|
-
super
|
23
|
-
ns_make_executor_runnable
|
24
|
-
end
|
25
|
-
|
26
21
|
def post(*args, &task)
|
27
22
|
raise ArgumentError.new('no block given') unless block_given?
|
28
23
|
return handle_fallback(*args, &task) unless running?
|
29
|
-
@executor.
|
24
|
+
@executor.submit Job.new(args, task)
|
30
25
|
true
|
31
26
|
rescue Java::JavaUtilConcurrent::RejectedExecutionException
|
32
27
|
raise RejectedExecutionError
|
@@ -43,7 +38,6 @@ if Concurrent.on_jruby?
|
|
43
38
|
|
44
39
|
def shutdown
|
45
40
|
synchronize do
|
46
|
-
self.ns_auto_terminate = false
|
47
41
|
@executor.shutdown
|
48
42
|
nil
|
49
43
|
end
|
@@ -51,7 +45,6 @@ if Concurrent.on_jruby?
|
|
51
45
|
|
52
46
|
def kill
|
53
47
|
synchronize do
|
54
|
-
self.ns_auto_terminate = false
|
55
48
|
@executor.shutdownNow
|
56
49
|
nil
|
57
50
|
end
|
@@ -75,14 +68,6 @@ if Concurrent.on_jruby?
|
|
75
68
|
@executor.isShutdown || @executor.isTerminated
|
76
69
|
end
|
77
70
|
|
78
|
-
def ns_make_executor_runnable
|
79
|
-
if !defined?(@executor.submit_runnable)
|
80
|
-
@executor.class.class_eval do
|
81
|
-
java_alias :submit_runnable, :submit, [java.lang.Runnable.java_class]
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
71
|
class Job
|
87
72
|
include Runnable
|
88
73
|
def initialize(args, block)
|
@@ -96,5 +81,23 @@ if Concurrent.on_jruby?
|
|
96
81
|
end
|
97
82
|
private_constant :Job
|
98
83
|
end
|
84
|
+
|
85
|
+
class DaemonThreadFactory
|
86
|
+
# hide include from YARD
|
87
|
+
send :include, java.util.concurrent.ThreadFactory
|
88
|
+
|
89
|
+
def initialize(daemonize = true)
|
90
|
+
@daemonize = daemonize
|
91
|
+
end
|
92
|
+
|
93
|
+
def newThread(runnable)
|
94
|
+
thread = java.util.concurrent.Executors.defaultThreadFactory().newThread(runnable)
|
95
|
+
thread.setDaemon(@daemonize)
|
96
|
+
return thread
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
private_constant :DaemonThreadFactory
|
101
|
+
|
99
102
|
end
|
100
103
|
end
|
@@ -17,12 +17,13 @@ if Concurrent.on_jruby?
|
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
|
-
|
20
|
+
|
21
21
|
def ns_initialize(opts)
|
22
|
-
@executor = java.util.concurrent.Executors.newSingleThreadExecutor
|
22
|
+
@executor = java.util.concurrent.Executors.newSingleThreadExecutor(
|
23
|
+
DaemonThreadFactory.new(ns_auto_terminate?)
|
24
|
+
)
|
23
25
|
@fallback_policy = opts.fetch(:fallback_policy, :discard)
|
24
26
|
raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy)
|
25
|
-
self.auto_terminate = opts.fetch(:auto_terminate, true)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
@@ -90,10 +90,10 @@ if Concurrent.on_jruby?
|
|
90
90
|
private
|
91
91
|
|
92
92
|
def ns_initialize(opts)
|
93
|
-
min_length
|
94
|
-
max_length
|
95
|
-
idletime
|
96
|
-
@max_queue
|
93
|
+
min_length = opts.fetch(:min_threads, DEFAULT_MIN_POOL_SIZE).to_i
|
94
|
+
max_length = opts.fetch(:max_threads, DEFAULT_MAX_POOL_SIZE).to_i
|
95
|
+
idletime = opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT).to_i
|
96
|
+
@max_queue = opts.fetch(:max_queue, DEFAULT_MAX_QUEUE_SIZE).to_i
|
97
97
|
@fallback_policy = opts.fetch(:fallback_policy, :abort)
|
98
98
|
|
99
99
|
raise ArgumentError.new("`max_threads` cannot be less than #{DEFAULT_MIN_POOL_SIZE}") if max_length < DEFAULT_MIN_POOL_SIZE
|
@@ -109,12 +109,16 @@ if Concurrent.on_jruby?
|
|
109
109
|
end
|
110
110
|
|
111
111
|
@executor = java.util.concurrent.ThreadPoolExecutor.new(
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
min_length,
|
113
|
+
max_length,
|
114
|
+
idletime,
|
115
|
+
java.util.concurrent.TimeUnit::SECONDS,
|
116
|
+
queue,
|
117
|
+
DaemonThreadFactory.new(ns_auto_terminate?),
|
118
|
+
FALLBACK_POLICY_CLASSES[@fallback_policy].new)
|
115
119
|
|
116
|
-
self.auto_terminate = opts.fetch(:auto_terminate, true)
|
117
120
|
end
|
118
121
|
end
|
122
|
+
|
119
123
|
end
|
120
124
|
end
|
@@ -27,7 +27,6 @@ module Concurrent
|
|
27
27
|
def shutdown
|
28
28
|
synchronize do
|
29
29
|
break unless running?
|
30
|
-
self.ns_auto_terminate = false
|
31
30
|
stop_event.set
|
32
31
|
ns_shutdown_execution
|
33
32
|
end
|
@@ -37,7 +36,6 @@ module Concurrent
|
|
37
36
|
def kill
|
38
37
|
synchronize do
|
39
38
|
break if shutdown?
|
40
|
-
self.ns_auto_terminate = false
|
41
39
|
stop_event.set
|
42
40
|
ns_kill_execution
|
43
41
|
stopped_event.set
|