Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple JRuby worker pool using j.u.c.Executors
# encoding: utf-8
require 'java'
module JUC
java_import 'java.util.concurrent.Executors'
java_import 'java.util.concurrent.TimeUnit'
end
class WorkerPool
def initialize(options={})
pool_size = options[:size] || self.class.default_size
@pool = JUC::Executors.new_fixed_thread_pool(pool_size)
end
def self.default_size
java.lang.Runtime.runtime.available_processors
end
def submit(&block)
@pool.submit(block)
end
def shutdown(wait=true)
@pool.shutdown
end
def await_termination(options={})
if options[:poll]
until @pool.await_termination(options[:timeout] || 1, JUC::TimeUnit::SECONDS)
yield if block_given?
end
else
@pool.await_termination(options[:timeout] || 300, JUC::TimeUnit::SECONDS)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.