1

How do I do this?

include Java
Thread.currentThread.sleep 3

I saw a posting from several years ago but it did not directly answer the question.

thx

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560

1 Answers1

2

Either:

Java::JavaLang::Thread::sleep 3

or

Java::JavaLang::Thread.sleep 3

(Note that the static call sleep() on Thread causes the current thread to sleep, so no need to call currentThread(), and that sleep time is in millisecond).

Here is an example (if you use JRuby prior to 1.7, you will need to add require 'java'):

t = Java::JavaLang::Thread.new do
  puts "Hi."
  Java::JavaLang::Thread::sleep 3000
  puts "Done."
end
t.start 
Sébastien Le Callonnec
  • 26,254
  • 8
  • 67
  • 80