ThreadGroup: getParent() : ThreadGroup « java.lang « Java by API






ThreadGroup: getParent()

 

public class Main {
  public static void main(String[] argv) throws Exception {
    ThreadGroup group = Thread.currentThread().getThreadGroup().getParent();
    while (group.getParent() != null) {
      group = group.getParent();
    }
    int numThreads = group.activeCount();
    Thread[] threads = new Thread[numThreads * 2];
    numThreads = group.enumerate(threads, false);

    for (int i = 0; i < numThreads; i++) {
      Thread thread = threads[i];
      System.out.println(thread.getName());
    }

    int numGroups = group.activeGroupCount();
    ThreadGroup[] groups = new ThreadGroup[numGroups * 2];
    numGroups = group.enumerate(groups, false);

    for (int i = 0; i < numGroups; i++) {
      System.out.println(groups[i]);
    }
  }
}

   
  








Related examples in the same category

1.new ThreadGroup(String groupName)
2.ThreadGroup: activeCount()
3.ThreadGroup: activeGroupCount()
4.ThreadGroup: enumerate(Thread[] thread)
5.ThreadGroup: getName()
6.ThreadGroup: list()