Skip to content

Commit e3ff810

Browse files
committed
Fix new failing specs
1 parent 35b1c52 commit e3ff810

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

lib/concurrent/executor/java_fixed_thread_pool.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@ class JavaFixedThreadPool < JavaThreadPoolExecutor
1717
#
1818
# @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool-int-
1919
def initialize(num_threads, opts = {})
20-
@overflow_policy = opts.fetch(:overflow_policy, :abort)
21-
@max_queue = 0
2220

23-
raise ArgumentError.new('number of threads must be greater than zero') if num_threads < 1
24-
raise ArgumentError.new("#{@overflow_policy} is not a valid overflow policy") unless OVERFLOW_POLICIES.keys.include?(@overflow_policy)
21+
opts = {
22+
min_threads: num_threads,
23+
max_threads: num_threads
24+
}.merge(opts)
25+
super(opts)
2526

26-
@executor = java.util.concurrent.Executors.newFixedThreadPool(num_threads)
27-
@executor.setRejectedExecutionHandler(OVERFLOW_POLICIES[@overflow_policy].new)
27+
28+
#@overflow_policy = opts.fetch(:overflow_policy, :abort)
29+
#@max_queue = 0
30+
#
31+
#raise ArgumentError.new('number of threads must be greater than zero') if num_threads < 1
32+
#raise ArgumentError.new("#{@overflow_policy} is not a valid overflow policy") unless OVERFLOW_POLICIES.keys.include?(@overflow_policy)
33+
#
34+
#@executor = java.util.concurrent.Executors.newFixedThreadPool(num_threads)
35+
#@executor.setRejectedExecutionHandler(OVERFLOW_POLICIES[@overflow_policy].new)
2836

2937
set_shutdown_hook
3038
end

lib/concurrent/executor/java_thread_pool_executor.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def initialize(opts = {})
7171

7272
raise ArgumentError.new('max_threads must be greater than zero') if max_length <= 0
7373
raise ArgumentError.new('min_threads cannot be less than zero') if min_length < 0
74+
raise ArgumentError.new('min_threads cannot be more than max_threads') if min_length > max_length
7475
raise ArgumentError.new("#{@overflow_policy} is not a valid overflow policy") unless OVERFLOW_POLICIES.keys.include?(@overflow_policy)
7576

7677
if min_length == 0 && @max_queue == 0
@@ -171,16 +172,7 @@ def status
171172
#
172173
# @return [Boolean] `true` when running, `false` when shutting down or shutdown
173174
def running?
174-
super && ! @executor.isTerminating
175-
end
176-
177-
# Begin an orderly shutdown. Tasks already in the queue will be executed,
178-
# but no new tasks will be accepted. Has no additional effect if the
179-
# thread pool is not running.
180-
def shutdown
181-
super
182-
@executor.getQueue.clear
183-
nil
175+
super && !@executor.isTerminating
184176
end
185177
end
186178
end

lib/concurrent/executor/ruby_fixed_thread_pool.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ def initialize(num_threads, opts = {})
1919
raise ArgumentError.new('number of threads must be greater than zero') if num_threads < 1
2020
raise ArgumentError.new("#{overflow_policy} is not a valid overflow policy") unless OVERFLOW_POLICIES.include?(overflow_policy)
2121

22-
opts = opts.merge(
22+
opts = {
2323
min_threads: num_threads,
2424
max_threads: num_threads,
25-
num_threads: overflow_policy,
25+
overflow_policy: overflow_policy,
2626
max_queue: DEFAULT_MAX_QUEUE_SIZE,
27-
idletime: 0
28-
)
27+
idletime: DEFAULT_THREAD_IDLETIMEOUT,
28+
}.merge(opts)
2929
super(opts)
3030
end
3131
end

lib/concurrent/executor/ruby_thread_pool_executor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def initialize(opts = {})
8686
raise ArgumentError.new('max_threads must be greater than zero') if @max_length <= 0
8787
raise ArgumentError.new('min_threads cannot be less than zero') if @min_length < 0
8888
raise ArgumentError.new("#{overflow_policy} is not a valid overflow policy") unless OVERFLOW_POLICIES.include?(@overflow_policy)
89+
raise ArgumentError.new('min_threads cannot be more than max_threads') if min_length > max_length
8990

9091
init_executor
9192

0 commit comments

Comments
 (0)