Using JRuby native Queue to manage work across threads
In this code snippet, I’ll show an example of how to use a native Ruby Queue to manage work across threads. I used JRuby to not be bound by a global interpreter lock, which allows use of all CPU cores at once. The code uses “java.lang.Runtime.getRuntime.available_processors” to get a count of the number of CPU cores and “tput cols” to get the column width of your terminal (although it did not work perfect in my environment, sometimes defaulting to 80). When executed you should see the activity of all your CPU cores max out, and clusters of “*” (based on the number of CPU cores) should print across your terminal.