private static void showThreads(PrintStream pw, ThreadGroup g, Thread current) {
    int nthreads = g.activeCount();
    pw.println("\nThread Group = " + g.getName() + " activeCount= " + nthreads);
    Thread[] tarray = new Thread[nthreads];
    int n = g.enumerate(tarray, false);

    for (int i = 0; i < n; i++) {
      Thread thread = tarray[i];
      ClassLoader loader = thread.getContextClassLoader();
      String loaderName = (loader == null) ? "Default" : loader.getClass().getName();
      Thread.State state = thread.getState();
      long id = thread.getId();
      pw.print("   " + id + " " + thread.getName() + " " + state + " " + loaderName);
      if (thread == current) pw.println(" **** CURRENT ***");
      else pw.println();
    }

    int ngroups = g.activeGroupCount();
    ThreadGroup[] garray = new ThreadGroup[ngroups];
    int ng = g.enumerate(garray, false);
    for (int i = 0; i < ng; i++) {
      ThreadGroup nested = garray[i];
      showThreads(pw, nested, current);
    }
  }
Exemple #2
0
 private static void dumptg(ThreadGroup tg, PrintWriter out, int indent) {
   for (int o = 0; o < indent; o++) out.print("\t");
   out.println("G: \"" + tg.getName() + "\"");
   Thread[] ths = new Thread[tg.activeCount() * 2];
   ThreadGroup[] tgs = new ThreadGroup[tg.activeGroupCount() * 2];
   int nt = tg.enumerate(ths, false);
   int ng = tg.enumerate(tgs, false);
   for (int i = 0; i < nt; i++) {
     Thread ct = ths[i];
     for (int o = 0; o < indent + 1; o++) out.print("\t");
     out.println("T: \"" + ct.getName() + "\"");
   }
   for (int i = 0; i < ng; i++) {
     ThreadGroup cg = tgs[i];
     dumptg(cg, out, indent + 1);
   }
 }