class PWork::ThreadPool
Public Class Methods
new(threads: 5)
click to toggle source
# File lib/pwork/jruby/thread_pool.rb, line 6 def initialize(threads: 5) @processes = [] @executor = java.util.concurrent.Executors::newFixedThreadPool threads end
Public Instance Methods
execute(&block)
click to toggle source
This method is called to pass a block to be ran on a thread within the thread pool
# File lib/pwork/jruby/thread_pool.rb, line 12 def execute(&block) thread_vars = PWork::Helpers::Threads.get_thread_vars @executor.execute do PWork::Helpers::Threads.set_thread_vars(thread_vars) block.call end end
shutdown()
click to toggle source
# File lib/pwork/jruby/thread_pool.rb, line 20 def shutdown @executor.shutdown end