@@ -25,14 +25,9 @@ class JavaThreadPoolExecutor
25
25
26
26
# The maximum number of tasks that may be waiting in the work queue at any one time.
27
27
# When the queue size reaches `max_queue` subsequent tasks will be rejected in
28
- # accordance with the configured `overflow_policy `.
28
+ # accordance with the configured `fallback_policy `.
29
29
attr_reader :max_queue
30
30
31
- # The policy defining how rejected tasks (tasks received once the queue size reaches
32
- # the configured `max_queue`) are handled. Must be one of the values specified in
33
- # `OVERFLOW_POLICIES`.
34
- attr_reader :overflow_policy
35
-
36
31
# Create a new thread pool.
37
32
#
38
33
# @param [Hash] opts the options which configure the thread pool
@@ -45,27 +40,28 @@ class JavaThreadPoolExecutor
45
40
# number of seconds a thread may be idle before being reclaimed
46
41
# @option opts [Integer] :max_queue (DEFAULT_MAX_QUEUE_SIZE) the maximum
47
42
# number of tasks allowed in the work queue at any one time; a value of
48
- # zero means the queue may grow without bounnd
49
- # @option opts [Symbol] :overflow_policy (:abort) the policy for handling new
50
- # tasks that are received when the queue size has reached `max_queue`
43
+ # zero means the queue may grow without bound
44
+ # @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
45
+ # tasks that are received when the queue size has reached
46
+ # `max_queue` or the executir has shut down
51
47
#
52
48
# @raise [ArgumentError] if `:max_threads` is less than one
53
49
# @raise [ArgumentError] if `:min_threads` is less than zero
54
- # @raise [ArgumentError] if `:overflow_policy ` is not one of the values specified
55
- # in `OVERFLOW_POLICIES `
50
+ # @raise [ArgumentError] if `:fallback_policy ` is not one of the values specified
51
+ # in `FALLBACK_POLICIES `
56
52
#
57
53
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html
58
54
def initialize ( opts = { } )
59
55
min_length = opts . fetch ( :min_threads , DEFAULT_MIN_POOL_SIZE ) . to_i
60
56
max_length = opts . fetch ( :max_threads , DEFAULT_MAX_POOL_SIZE ) . to_i
61
57
idletime = opts . fetch ( :idletime , DEFAULT_THREAD_IDLETIMEOUT ) . to_i
62
58
@max_queue = opts . fetch ( :max_queue , DEFAULT_MAX_QUEUE_SIZE ) . to_i
63
- @overflow_policy = opts . fetch ( :overflow_policy , :abort )
59
+ @fallback_policy = opts . fetch ( :fallback_policy , opts . fetch ( : overflow_policy, :abort ) )
64
60
65
61
raise ArgumentError . new ( 'max_threads must be greater than zero' ) if max_length <= 0
66
62
raise ArgumentError . new ( 'min_threads cannot be less than zero' ) if min_length < 0
67
63
raise ArgumentError . new ( 'min_threads cannot be more than max_threads' ) if min_length > max_length
68
- raise ArgumentError . new ( "#{ @overflow_policy } is not a valid overflow policy" ) unless OVERFLOW_POLICIES . keys . include? ( @overflow_policy )
64
+ raise ArgumentError . new ( "#{ fallback_policy } is not a valid fallback policy" ) unless FALLBACK_POLICIES . include? ( @fallback_policy )
69
65
70
66
if @max_queue == 0
71
67
queue = java . util . concurrent . LinkedBlockingQueue . new
@@ -76,7 +72,7 @@ def initialize(opts = {})
76
72
@executor = java . util . concurrent . ThreadPoolExecutor . new (
77
73
min_length , max_length ,
78
74
idletime , java . util . concurrent . TimeUnit ::SECONDS ,
79
- queue , OVERFLOW_POLICIES [ @overflow_policy ] . new )
75
+ queue , FALLBACK_POLICIES [ @fallback_policy ] . new )
80
76
81
77
set_shutdown_hook
82
78
end
0 commit comments