Skip to content

Instantly share code, notes, and snippets.

@pmahoney
Created October 3, 2012 20:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pmahoney/3829759 to your computer and use it in GitHub Desktop.
Save pmahoney/3829759 to your computer and use it in GitHub Desktop.
executors in jruby example
require 'java'
class Task
include Java::JavaUtilConcurrent::Callable
def initialize(num)
@num = num
end
def call
puts "This is task #{@num}"
sleep 0.2
@num
end
end
Executors = Java::JavaUtilConcurrent::Executors
executor = Executors.newFixedThreadPool(8)
futures = (1..100).map do |i|
executor.submit Task.new(i)
end
rets = futures.map { |f| f.get }
puts "return values: #{rets.join(',')}"
executor.shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment