// Find the root thread group and list it recursively
public static void listAllThreads(PrintStream out) {
ThreadGroup curr_thread_group;
ThreadGroup root_thread_group;
ThreadGroup parent;
curr_thread_group = Thread.currentThread().getThreadGroup();
// Now go find the root thread group
root_thread_group = curr_thread_group;
parent = root_thread_group.getParent();
while(parent != null) {
root_thread_group = parent;
parent = parent.getParent();
}
list_group(out, root_thread_group, ""); // And list it, recursively
}
public static void main(String[] args) {
Thread t = Thread.currentThread();
System.out.println ("from main: " + t);
ThreadLister.listAllThreads(System.out);
System.out.println ("from main: " + t);
}
} // end ThreadLister
Previous slide | Next slide | Back to first slide | View graphic version |