Kernel.sleep swallows InterruptedException, which means that it doesn't play well with, for example, ExecutorService#shutdown_now.
I've written two test cases that demonstrate the issue:
https://github.com/iconara/jruby/compare/sleep_interrupt_test
The tests show how sleep ignores interrupts. When the thread that is sleeping is interrupted they should either rethrow the InterruptedException or at least unblock and set the interrupt flag, but both of them instead sleeps until as long as they would have had there been no interrupt. If you change sleep to java.lang.Thread.sleep they would both succeed.
I would have liked to be able to give you a complete patch for this, the fix should be simple: just don't swallow the exception, but the compiler won't allow me to declare sleep to throw InterruptedException, I'm not sure what's going on, I don't know enough about the JRuby code base to do it unfortunately.
It looks like it's been like this forever (I've traced the code back to a commit 11 years ago...), and maybe there's a lot of code out there that could potentially break if sleep was changed to be more Java friendly.
|