Java ThreadGroup.getParent()
Syntax
ThreadGroup.getParent() has the following syntax.
public final ThreadGroup getParent()
Example
In the following code shows how to use ThreadGroup.getParent() method.
//from www. j a va 2 s. co m
public class Main {
public static void main(String[] args) {
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();
System.out.println("ParentThreadGroup for " + pGroup.getName() + " is "
+ pGroup.getParent().getName());
System.out.println("ParentThreadGroup for " + cGroup.getName() + " is "
+ cGroup.getParent().getName());
}
public void run() {
System.out.println(Thread.currentThread().getName()
+ " finished executing.");
}
}