Example usage for java.lang ThreadGroup isDaemon

List of usage examples for java.lang ThreadGroup isDaemon

Introduction

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

Prototype

public final boolean isDaemon() 

Source Link

Document

Tests if this thread group is a daemon thread group.

Usage

From source file:ThreadLister.java

/** Display info about a thread group */
private static void printGroupInfo(ThreadGroup g, String indent) {
    if (g == null)
        return;//from  w  w  w . j a v a  2  s  .com
    int numThreads = g.activeCount();
    int numGroups = g.activeGroupCount();
    Thread[] threads = new Thread[numThreads];
    ThreadGroup[] groups = new ThreadGroup[numGroups];

    g.enumerate(threads, false);
    g.enumerate(groups, false);

    System.out.println(indent + "Thread Group: " + g.getName() + "  Max Priority: " + g.getMaxPriority()
            + (g.isDaemon() ? " Daemon" : ""));

    for (int i = 0; i < numThreads; i++)
        printThreadInfo(threads[i], indent + "    ");
    for (int i = 0; i < numGroups; i++)
        printGroupInfo(groups[i], indent + "    ");
}

From source file:ThreadLister.java

/** Display info about a thread group and its threads and groups */
private static void printGroupInfo(PrintWriter out, ThreadGroup g, String indent) {
    if (g == null)
        return;//from  w  ww .  j  a  v  a2s . c  o  m
    int num_threads = g.activeCount();
    int num_groups = g.activeGroupCount();
    Thread[] threads = new Thread[num_threads];
    ThreadGroup[] groups = new ThreadGroup[num_groups];

    g.enumerate(threads, false);
    g.enumerate(groups, false);

    out.println(indent + "Thread Group: " + g.getName() + "  Max Priority: " + g.getMaxPriority()
            + (g.isDaemon() ? " Daemon" : ""));

    for (int i = 0; i < num_threads; i++)
        printThreadInfo(out, threads[i], indent + "    ");
    for (int i = 0; i < num_groups; i++)
        printGroupInfo(out, groups[i], indent + "    ");
}

From source file:Main.java

/**
 * Display info about a thread group and its threads and groups
 *//* ww w .j a  v  a 2 s .c  om*/
private static void printGroupInfo(PrintWriter out, ThreadGroup g, String indent) {
    if (g == null) {
        return;
    }
    int num_threads = g.activeCount();
    int num_groups = g.activeGroupCount();
    Thread[] threads = new Thread[num_threads];
    ThreadGroup[] groups = new ThreadGroup[num_groups];

    g.enumerate(threads, false);
    g.enumerate(groups, false);

    out.println(indent + "Thread Group: " + g.getName() + "  Max Priority: " + g.getMaxPriority()
            + (g.isDaemon() ? " Daemon" : ""));

    for (int i = 0; i < num_threads; i++) {
        printThreadInfo(out, threads[i], indent + "    ");
    }
    for (int i = 0; i < num_groups; i++) {
        printGroupInfo(out, groups[i], indent + "    ");
    }
}

From source file:Main.java

/** Collect info about a thread group */
private static void collectThreadGroupInfo(final ThreadGroup g, final StringBuffer str, final String indent) {
    if (g == null) {
        return;/*from   w w w . jav a  2 s. co  m*/
    }
    int numThreads = g.activeCount();
    int numGroups = g.activeGroupCount();
    final Thread[] threads = new Thread[numThreads * 2];
    final ThreadGroup[] groups = new ThreadGroup[numGroups * 2];

    numThreads = g.enumerate(threads, false);
    numGroups = g.enumerate(groups, false);

    str.append(indent).append("Thread Group: [").append(g.getName()).append("]  Max Priority: [")
            .append(g.getMaxPriority()).append(g.isDaemon() ? " Daemon" : "").append("]")
            .append(LINE_SEPARATOR);

    for (int i = 0; i < numThreads; i++) {
        if (threads[i] != null) {
            collectThreadInfo(threads[i], str, indent + "    ");
        }
    }
    for (int i = 0; i < numGroups; i++) {
        collectThreadGroupInfo(groups[i], str, indent + "    ");
    }
}

From source file:Main.java

public ThreadGroupDemo() {

    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");
    pGroup.setDaemon(true);/*from  w  ww.  j a  v a  2  s .  c  om*/

    ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");
    cGroup.setDaemon(true);

    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("Is " + pGroup.getName() + " a daemon ThreadGroup? " + pGroup.isDaemon());
    System.out.println("Is " + cGroup.getName() + " a daemon ThreadGroup? " + cGroup.isDaemon());

}

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   w  ww . j  a  va2 s  . com*/

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

    System.out.println("Active threads in " + pGroup.getName() + " = " + pGroup.activeCount());

    System.out.println("Is " + pGroup.getName() + " a daemon ThreadGroup? " + pGroup.isDaemon());
    System.out.println("Is " + cGroup.getName() + " a daemon ThreadGroup? " + cGroup.isDaemon());
}