Example usage for java.lang ThreadGroup getParent

List of usage examples for java.lang ThreadGroup getParent

Introduction

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

Prototype

public final ThreadGroup getParent() 

Source Link

Document

Returns the parent of this thread group.

Usage

From source file:Main.java

/**
 * Get the top thread group of this JVM.
 *
 * @return the top thread group//from w ww  . j av a2  s.c  o  m
 */
public static final ThreadGroup topGroup() {
    ThreadGroup topGroup = Thread.currentThread().getThreadGroup();
    ThreadGroup pareGroup = topGroup.getParent();
    // Iterate through the group link.
    while (pareGroup != null) {
        topGroup = pareGroup;
        pareGroup = pareGroup.getParent();
    }
    return topGroup;
}

From source file:Main.java

/**
 * Gets the "root" thread group for the entire JVM.  Internally, first get
 * the current thread and its thread group. Then get its parent group, then
 * its parent group, and on up until you find a group with a null parent.
 * That's the root ThreadGroup.  Since the same root thread group is used
 * for the life of the JVM, you can safely cache it for faster future use.
 * @return The root thread group for the JVM
 *//* w  w  w.ja  v a  2  s  .c  o  m*/
static public ThreadGroup getRootThreadGroup() {
    ThreadGroup tg = Thread.currentThread().getThreadGroup();
    ThreadGroup ptg;
    while ((ptg = tg.getParent()) != null)
        tg = ptg;
    return tg;
}

From source file:Main.java

/**
 * Get all threads//from   www  .j av a  2s. c  o m
 * 
 * @return
 */
public static String[] getThreadNames() {
    ThreadGroup group = Thread.currentThread().getThreadGroup();
    ThreadGroup parent = null;
    while ((parent = group.getParent()) != null) {
        group = parent;
    }
    Thread[] threads = new Thread[group.activeCount()];
    group.enumerate(threads);
    HashSet<String> set = new HashSet<String>();

    for (int i = 0; i < threads.length; ++i) {
        if (threads[i] != null && threads[i].isAlive()) {
            try {
                set.add(threads[i].getThreadGroup().getName() + ", " + threads[i].getName() + ", "
                        + threads[i].getPriority() + ", " + threads[i].getState());
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
    String[] result = (String[]) set.toArray(new String[0]);
    Arrays.sort(result);

    for (int i = 0; i < result.length; i++) {
        //         logger.debug(result[i]);
    }

    return result;
}

From source file:Main.java

/** Returns a {@link String} containing an enumeration of all {@link Thread}s in all {@link ThreadGroup}s. */
public static String enumerateAllThreads() {
    ThreadGroup root = Thread.currentThread().getThreadGroup();

    // climb up the tree until we read the parent group
    while (root.getParent() != null) {
        root = root.getParent();/*ww  w .j  a v a2  s. c  om*/
    }

    final StringBuffer str = new StringBuffer();
    collectThreadGroupInfo(root, str, "");

    return str.toString();
}

From source file:Main.java

public static ThreadGroup getRootThreadGroup() {
    ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
    ThreadGroup parentThreadGroup;

    while ((parentThreadGroup = threadGroup.getParent()) != null) {
        threadGroup = parentThreadGroup;
    }/*from  ww w  .jav a2  s .c  om*/

    return threadGroup;
}

From source file:org.eclipse.objectteams.otequinox.internal.hook.Util.java

private static int getActiveCount() {
    ThreadGroup group = Thread.currentThread().getThreadGroup();
    ThreadGroup parent = group.getParent();
    while (parent != null) {
        group = parent;// www  .  j  a v  a  2 s . c  o  m
        parent = group.getParent();
    }
    return group.activeCount();
}

From source file:Main.java

/**
 * Get the root thread group in the thread group tree.
 * Since there is always a root thread group, this
 * method never returns null.//from w  w w.  j av a 2 s  .  c o m
 *
 * @return      the root thread group
 */
public static ThreadGroup getRootThreadGroup() {
    if (rootThreadGroup != null)
        return rootThreadGroup;

    ThreadGroup tg = Thread.currentThread().getThreadGroup();
    ThreadGroup ptg;
    while ((ptg = tg.getParent()) != null)
        tg = ptg;
    rootThreadGroup = tg;
    return tg;
}

From source file:Main.java

private static ThreadGroup getRootThreadGroup() {
    ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
    ThreadGroup parentThreadGroup;

    while ((parentThreadGroup = threadGroup.getParent()) != null) {
        threadGroup = parentThreadGroup;
    }/*from  w  w  w.  j  ava  2  s.  co  m*/

    return threadGroup;
}

From source file:ThreadLister.java

/** Find the root thread group and list it recursively */
public static void listAllThreads() {
    ThreadGroup currentThreadGroup;
    ThreadGroup rootThreadGroup;
    ThreadGroup parent;/* w w  w .  j  av a 2 s.co  m*/

    // Get the current thread group
    currentThreadGroup = Thread.currentThread().getThreadGroup();

    // Now go find the root thread group
    rootThreadGroup = currentThreadGroup;
    parent = rootThreadGroup.getParent();
    while (parent != null) {
        rootThreadGroup = parent;
        parent = parent.getParent();
    }

    printGroupInfo(rootThreadGroup, "");
}

From source file:org.nuxeo.runtime.management.jvm.ThreadDeadlocksDetector.java

protected static ThreadGroup rootGroup(ThreadGroup group) {
    ThreadGroup parent = group.getParent();
    if (parent == null) {
        return group;
    }/*from w  ww .  j  a  va  2s . co m*/
    return rootGroup(parent);
}