next up previous contents
Next: Threads Example 8.2: Max Up: Java Notes Previous: Threads: ThreadGroup Examples:

Threads Example 8.1: Enumerate

/**
 * Adapted from The Java Tutorial
 * Second Edition by Campione, M. and
 * Walrath, K.Addison-Wesley 1998
 */
class EnumerateTest{
  public void listCurrentThreads(){
	ThreadGroup currentGroup = 
		Thread.currentThread().getThreadGroup();
	int numThreads = currentGroup.activeCount();
	Thread[] listOfThreads = new Thread[numThreads];
	currentGroup.enumerate(listOfThreads);
	for (int i = 0; i < numThreads; i++)
	  System.out.println("Thread #" + i + " = " + 
						 listOfThreads[i].getName());
  }
}
public class EnumerateMain{
  public static void main(String[] args){
	new EnumerateTest().listCurrentThreads();
  }
}



Ananda Amatya
9/15/1999