Java ThreadGroup.enumerate(Thread [] list)

Syntax

ThreadGroup.enumerate(Thread [] list) has the following syntax.

public int enumerate(Thread [] list)

Example

In the following code shows how to use ThreadGroup.enumerate(Thread [] list) method.


public class Main {
/* ww  w .  j  a  v a  2s  . c  o  m*/
  public static void main(String[] args) {
    ThreadGroupDemo tg = new ThreadGroupDemo();

  }
}

class ThreadGroupDemo implements Runnable {
  public ThreadGroupDemo() {

         ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");
    
         ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

         Thread t1 = new Thread(pGroup, this);
         System.out.println("Starting " + t1.getName());
         t1.start();
            
         Thread t2 = new Thread(cGroup, this);
         System.out.println("Starting " + t2.getName());
         t2.start();
            
         Thread[] list = new Thread[pGroup.activeCount()];
         int count = pGroup.enumerate(list);
         for (int i = 0; i < count; i++) {
            System.out.println("Thread " + list[i].getName() + " found");
         }

   }

   // implements run()
   public void run() {

      System.out.println(Thread.currentThread().getName() + 
      " finished executing.");
   }
}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable