-
-
Save cheald/eea7cbbcc2b90c81f243 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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