code: static public Thread[] getAllThreads() {
          final ThreadGroup root = getRootThreadGroup();
          final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
          int nAlloc = thbean.getThreadCount();
          int n = 0;
          Thread[] threads;
          do {
              nAlloc *= 2;
              threads = new Thread[nAlloc];
              n = root.enumerate(threads, true);
          } while (n == nAlloc);
          return java.util.Arrays.copyOf(threads, n);
      }
docs: Gets all threads in the JVM.  This is really a snapshot of all threads
  at the time this method is called.
  @return An array of all threads currently running in the JVM.