Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 0.33 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to count running threads in ruby server
  2. if (running_thread_count > 10)
  3.     stuff_that_takes_a_second()
  4. else
  5.     Thread.new do
  6.         stuff_that_takes_a_second()
  7.     end
  8. end
  9.        
  10. def running_thread_count
  11.  return Thread.list.count
  12. end
  13.        
  14. def running_thread_count
  15.   Thread.list.select {|thread| thread.status == "run"}.count
  16. end