Last active
December 10, 2015 07:18
-
-
Save capotej/4400248 to your computer and use it in GitHub Desktop.
basic skeleton for executing tasks in parallel in jruby
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' | |
java_import 'java.util.concurrent.ThreadPoolExecutor' | |
java_import 'java.util.concurrent.TimeUnit' | |
java_import 'java.util.concurrent.LinkedBlockingQueue' | |
java_import 'java.util.concurrent.FutureTask' | |
java_import 'java.util.concurrent.Callable' | |
java_import 'java.util.concurrent.Executors' | |
### SETTINGS | |
concurrency = 80 | |
times = concurrency * 100 | |
### END SETTINGS | |
executor = Executors.newFixedThreadPool(concurrency) | |
class ThreadTest | |
include Callable | |
def call | |
sleep 5 | |
print "." | |
end | |
end | |
puts "starting" | |
tasks = [] | |
times.times { tasks << ThreadTest.new } | |
executor.invokeAll(tasks) | |
puts "ending" | |
executor.shutdown | |
executor.awaitTermination(2, TimeUnit::MINUTES) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment