Get root thread group - Java java.lang

Java examples for java.lang:Thread

Description

Get root thread group

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getRootThreadGroup());
    }/*from   w  w w.  java 2  s .  com*/

    /**
     * Get root thread group
     *
     * @return root thread group
     */
    private static ThreadGroup getRootThreadGroup() {
        ThreadGroup root = Thread.currentThread().getThreadGroup();
        ThreadGroup parent = root.getParent();
        while (parent != null) {
            root = parent;
            parent = parent.getParent();
        }
        return root;
    }
}

Related Tutorials