Created
July 11, 2012 20:33
-
-
Save mrjabba/3093156 to your computer and use it in GitHub Desktop.
how to schedule a newScheduledThreadPool in jruby
This file contains 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.Executors' | |
java_import 'java.util.concurrent.TimeUnit' | |
class SomeClass | |
include java.lang.Runnable | |
def run | |
puts "imma lil jruby runner" | |
end | |
end | |
class Scheduler | |
def schedule | |
puts "starting..." | |
service = Executors.newScheduledThreadPool(1); | |
service.scheduleAtFixedRate(SomeClass.new, 4, 2, TimeUnit::SECONDS); | |
puts "i can haz service? #{service.class}" | |
puts "done..." | |
end | |
end | |
Scheduler.new.schedule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depending on what's in your real
SomeClass
, you might want to schedule a shutdown:This will tell the schedule not to start any new threads, and the second call will wait 2 seconds for any threads that are running to shut down. You could also do
shutdown_now
to force an exit (but callingexit
would likely do that, too :)