Naming Threads in JRuby

There are a lot of nice tools out there to get thread dumps, but they are much easier to interpret if threads have meaningful names. I have not been able to figure out a way to name a standard ruby thread, but in JRuby, you can always call on the underlying java APIs. So naming a thread is as easy as:

require "java"
java.lang.Thread.currentThread.setName("awesome thread name")

If you know a way to do this in pure ruby, please tell me how. I’d much rather not fall back to java, but in a pinch it’ll do.

Leave a Reply

Your email address will not be published. Required fields are marked *