public static void dumptg (ThreadGroup tg){
// First, get our thread group
if (tg == null){
// none specified, assume current thread group
tg = Thread.currentThread().getThreadGroup();
}
// display the threadgroup name and object id
System.out.println("ThreadGroup "+tg.getName()+ ", objid = "+tg.hashCode());
// display the threadgroup's number of active subgroups
System.out.println(" subgroups = "+tg.activeGroupCount());
// get and display the number of active threads in this threadgroup and all subgroups
int tcount = tg.activeCount();
System.out.println(" total threads = "+tcount);
// allocate an array big enough to hold the number of threads
Thread[] arr = new Thread[tcount];
// fill in the array with the active threads (include subgroups)
int num = tg.enumerate(arr,true);
// display how many were stored.
System.out.println("\nTHREADNAME, THREADID, THREADGROUP");
// display the name, id and owning threadgroup of each thread
for (int i = 0; i<num; i++){
System.out.println(arr[i].getName()+", "+
arr[i].hashCode()+", "+
arr[i].getThreadGroup().getName());
}
}