ThreadGroup: activeGroupCount()
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