code: public String getThreadDump(int depth, boolean onlyActive)
    {
      ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
  
      long []ids = threadBean.getAllThreadIds();
      ThreadInfo []info = threadBean.getThreadInfo(ids, depth);
  
      StringBuilder sb = new StringBuilder();
      sb.append("Thread Dump generated " + new Date(CurrentTime.currentTime()));
  
      Arrays.sort(info, new ThreadCompare());
      
      buildThreads(sb, info, Thread.State.RUNNABLE, false);
      buildThreads(sb, info, Thread.State.RUNNABLE, true);
      
      if (! onlyActive) {
        buildThreads(sb, info, Thread.State.BLOCKED, false);
        buildThreads(sb, info, Thread.State.WAITING, false);
        buildThreads(sb, info, Thread.State.TIMED_WAITING, false);
        buildThreads(sb, info, null, false);
      }
  
      return sb.toString();
    }
docs: Returns dump of threads.  Optionally uses cached dump.
  @param onlyActive if true only running threads are logged