code: private static void listAllThreads(final PrintWriter out) {
          final ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();
          ThreadGroup rootThreadGroup = currentThreadGroup;
          ThreadGroup parent = rootThreadGroup.getParent();
  
          while (parent != null) {
              rootThreadGroup = parent;
              parent = parent.getParent();
          }
  
          // And list it, recursively
          Util.printGroupInfo(out, rootThreadGroup, "");
      }
docs: Find the root thread group and list it recursively