Skip to content

Commit ae4331a

Browse files
committed
Do not allow running jobs with OneOnOne on executors which may averflow
1 parent b021a94 commit ae4331a

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

lib/concurrent/executor/executor.rb

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

66
module Executor
7+
def can_overflow?
8+
false
9+
end
710
end
811

912
module RubyExecutor

lib/concurrent/executor/java_thread_pool_executor.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def initialize(opts = {})
8989
set_shutdown_hook
9090
end
9191

92+
def can_overflow?
93+
@max_queue != 0
94+
end
95+
9296
# The minimum number of threads that may be retained in the pool.
9397
#
9498
# @return [Integer] the min_length

lib/concurrent/executor/one_by_one.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def initialize
3030
# @raise [ArgumentError] if no task is given
3131
def post(executor, *args, &task)
3232
return nil if task.nil?
33+
if executor.can_overflow?
34+
raise ArgumentError, 'OneByOne cannot be used in conjunction with executor which may overflow'
35+
end
36+
3337
job = Job.new executor, args, task
3438

3539
begin

lib/concurrent/executor/ruby_thread_pool_executor.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ def initialize(opts = {})
9999
@last_gc_time = Time.now.to_f - [1.0, (@gc_interval * 2.0)].max
100100
end
101101

102+
def can_overflow?
103+
@max_queue != 0
104+
end
105+
102106
# The number of threads currently in the pool.
103107
#
104108
# @return [Integer] the length

0 commit comments

Comments
 (0)