Example usage for java.lang ThreadGroup parentOf

List of usage examples for java.lang ThreadGroup parentOf

Introduction

In this page you can find the example usage for java.lang ThreadGroup parentOf.

Prototype

public final boolean parentOf(ThreadGroup g) 

Source Link

Document

Tests if this thread group is either the thread group argument or one of its ancestor thread groups.

Usage

From source file:Main.java

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();/*from   www  . j av  a2  s.  co  m*/

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();

    // determine which ThreadGroup is parent
    boolean isParent = pGroup.parentOf(cGroup);
    System.out.println(pGroup.getName() + " is the parent of " + cGroup.getName() + "? " + isParent);

    isParent = cGroup.parentOf(pGroup);
    System.out.println(cGroup.getName() + " is the parent of " + pGroup.getName() + "? " + isParent);

}