How can I get the number of active Groups within a ThreadGroup?

Brandon Rohlfs

ThreadGroups activeGroupCount() returns the number of active groups within the ThreadGroup instance it was called upon. Once the number of active groups is obtained ThreadGroups enumerate(ThreadGroup[]) can be used to copy all refrences of the active subgroups into a ThreadGroup[].

class EnumTest{
 public static void main(String[] args){
  ThreadGroup tgp = new ThreadGroup("Parent"); 
  ThreadGroup tgc1 = new ThreadGroup(tgp, "Child 1");
  ThreadGroup tgc2 = new ThreadGroup(tgc1, "Child 2");
  ThreadGroup[] tg = new ThreadGroup[tgp.activeGroupCount()];
  for(int i = 0; i < tg.length; ++i){
About | Sitemap | Contact