There is a race condition in the Thread.list function where it is possible to read the list before the thread has been added.
I first saw this issue in JRuby 1.4 and reported it (
JRUBY-4307), but the ticket was not solved. I haven't checked to see if the code has changed, but there is still an issue with this functionality in JRuby 1.7.
At the time, in 1.4, it was causing a problem with Active Record connection caching whereby connections were being closed by other threads while still in use because the thread list was incorrect. It only happened under heavy stress. The active record code is still using this functionality but I have not confirmed if the issue is still happening or not. See function clear_stale_cached_connections! (line 196) in jruby-1.7.0.preview1\lib\ruby\gems\shared\gems\activerecord-3.2.3\lib\active_record\connection_adapters\abstract\connection_pool.rb.
Another related ticket is
I am attaching a patch which fixes the issue in my test application.