@@ -12,7 +12,7 @@ module Concurrent
1212 class RubyThreadPoolExecutor < RubyExecutorService
1313
1414 # Default maximum number of threads that will be created in the pool.
15- DEFAULT_MAX_POOL_SIZE = 2 ** 13 # 8192
15+ DEFAULT_MAX_POOL_SIZE = 2_147_483_647 # java.lang.Integer::MAX_VALUE
1616
1717 # Default minimum number of threads that will be retained in the pool.
1818 DEFAULT_MIN_POOL_SIZE = 0
@@ -139,9 +139,10 @@ def ns_initialize(opts)
139139 raise ArgumentError . new ( "#{ @fallback_policy } is not a valid fallback policy" ) unless FALLBACK_POLICIES . include? ( @fallback_policy )
140140 deprecated ':overflow_policy is deprecated terminology, please use :fallback_policy instead' if opts . has_key? ( :overflow_policy )
141141
142- raise ArgumentError . new ( 'max_threads must be greater than zero' ) if @max_length <= 0
143- raise ArgumentError . new ( 'min_threads cannot be less than zero' ) if @min_length < 0
144- raise ArgumentError . new ( 'min_threads cannot be more than max_threads' ) if min_length > max_length
142+ raise ArgumentError . new ( "`max_threads` cannot be less than #{ DEFAULT_MIN_POOL_SIZE } " ) if @max_length < DEFAULT_MIN_POOL_SIZE
143+ raise ArgumentError . new ( "`max_threads` cannot be greater than #{ DEFAULT_MAX_POOL_SIZE } " ) if @max_length > DEFAULT_MAX_POOL_SIZE
144+ raise ArgumentError . new ( "`min_threads` cannot be less than #{ DEFAULT_MIN_POOL_SIZE } " ) if @min_length < DEFAULT_MIN_POOL_SIZE
145+ raise ArgumentError . new ( "`min_threads` cannot be more than `max_threads`" ) if min_length > max_length
145146
146147 self . auto_terminate = opts . fetch ( :auto_terminate , true )
147148
@@ -216,6 +217,9 @@ def ns_assign_worker(*args, &task)
216217 else
217218 false
218219 end
220+ rescue ThreadError
221+ # Raised when the operating system refuses to create the new thread
222+ return false
219223 end
220224
221225 # tries to enqueue task
0 commit comments