O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Listing All Threads

public static void listThreads() {
											ThreadGroup root = Thread.currentThread()
											.getThreadGroup().getParent();
											while (root.getParent() != null) {
											root = root.getParent();
											}
											visitGroup(root, 0);
											}
											public static void visitGroup(ThreadGroup group, int
											level) {
											int numThreads = group.activeCount();
											Thread[] threads = new Thread[numThreads];
											group.enumerate(threads, false);
											for (int i=0; i<numThreads; i++) {
											Thread thread = threads[i];
											printThreadInfo(thread);
											}
											int numGroups = group.activeGroupCount();
											ThreadGroup[] groups = new
											ThreadGroup[numGroups];
											numGroups = group.enumerate(groups, false);
											for (int i=0; i<numGroups; i++) {
											visitGroup(groups[i], level+1);
											}
											}
											private static void printThreadInfo(Thread t) {
											System.out.println("Thread: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required