Method: Traject::ThreadPool#initialize
- Defined in:
- lib/traject/thread_pool.rb
#initialize(pool_size) ⇒ ThreadPool
First arg is pool size, 0 or nil and we'll be a null/no-op pool
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/traject/thread_pool.rb', line 49 def initialize(pool_size) unless pool_size.nil? || pool_size == 0 require 'java' # trigger an exception now if we're not jruby @label = label @pool_size = pool_size.to_i # just for reflection, we don't really need it again @queue_capacity = pool_size * 3 blockingQueue = java.util.concurrent.ArrayBlockingQueue.new(@queue_capacity) rejectedExecutionHandler = java.util.concurrent.ThreadPoolExecutor::CallerRunsPolicy.new # keepalive times don't matter, we are setting core and max pool to # same thing, fixed size pool. @thread_pool = java.util.concurrent.ThreadPoolExecutor.new( @pool_size, @pool_size, 0, java.util.concurrent.TimeUnit::MILLISECONDS, blockingQueue, rejectedExecutionHandler) # A thread-safe queue to collect exceptions cross-threads. # We make it small, we really only need to store the first # exception, we don't care too much about others. But we'll # keep the first 20, why not. @async_exception_queue = java.util.concurrent.ArrayBlockingQueue.new(20) end end |