List of usage examples for java.lang ThreadGroup getParent
public final ThreadGroup getParent()
From source file:Main.java
public static void main(String[] argv) throws Exception { ThreadGroup group = Thread.currentThread().getThreadGroup().getParent(); while (group.getParent() != null) { group = group.getParent();/*from w w w . ja va 2 s . co m*/ } int numThreads = group.activeCount(); Thread[] threads = new Thread[numThreads * 2]; numThreads = group.enumerate(threads, false); for (int i = 0; i < numThreads; i++) { Thread thread = threads[i]; System.out.println(thread.getName()); } int numGroups = group.activeGroupCount(); ThreadGroup[] groups = new ThreadGroup[numGroups * 2]; numGroups = group.enumerate(groups, false); for (int i = 0; i < numGroups; i++) { System.out.println(groups[i]); } }
From source file:Main.java
public static void main(String[] args) throws Exception { ThreadGroup tg = Thread.currentThread().getThreadGroup(); MyThread mt1 = new MyThread(tg, "first"); MyThread mt2 = new MyThread(tg, "second"); mt1.start();//from w w w. jav a2 s . c om mt2.start(); ThreadGroup parent = tg.getParent(); Thread[] list = new Thread[parent.activeCount()]; int count = parent.enumerate(list, true); String[] thdinfo = new String[count]; for (int i = 0; i < count; i++) thdinfo[i] = list[i].toString(); mt1.join(); mt2.join(); for (int i = 0; i < count; i++) System.out.println(thdinfo[i]); }
From source file:Main.java
public static ThreadGroup getThreadRoot() { ThreadGroup root = Thread.currentThread().getThreadGroup(); while (root.getParent() != null) { root = root.getParent();/*from w ww . j a v a2 s. c o m*/ } return root; }
From source file:Main.java
public static ThreadGroup getRootThreadGroup() { ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); while (threadGroup.getParent() != null) { threadGroup = threadGroup.getParent(); }/*from www. j a v a 2 s . co m*/ return threadGroup; }
From source file:Main.java
public static ThreadGroup getRootThreadGroup() { ThreadGroup group = Thread.currentThread().getThreadGroup(); while (null != group.getParent()) { group = group.getParent();//from w ww .j a v a 2 s. c o m } return group; }
From source file:Main.java
public static Thread findThreadByName(String name) { ThreadGroup group = Thread.currentThread().getThreadGroup(); while (group.getParent() != null) group = group.getParent();/* w w w. j a v a2 s .com*/ Thread[] threadList = new Thread[group.activeCount() + 5]; group.enumerate(threadList, true); for (Thread thread : threadList) if (thread != null && thread.getName().equals(name)) return thread; return null; }
From source file:Main.java
public static ThreadGroup getRootThreadGroup() { ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); while (null != threadGroup.getParent()) { threadGroup = threadGroup.getParent(); }/*from w w w . j a va 2 s . c om*/ return threadGroup; }
From source file:Main.java
/** * Return the system thread group (sometimes also referred as "root thread group"). * * @return the system thread group/*from w w w . j a v a2s . c om*/ * @throws SecurityException if the current thread cannot modify * thread groups from this thread's thread group up to the system thread group */ public static ThreadGroup getSystemThreadGroup() { ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); while (threadGroup.getParent() != null) { threadGroup = threadGroup.getParent(); } return threadGroup; }
From source file:Main.java
public static String getThreadTree() { ThreadGroup root = Thread.currentThread().getThreadGroup(); while (root.getParent() != null) { root = root.getParent();// w w w .j a va 2 s . c o m } StringBuffer buffer = new StringBuffer(); buffer.append(root.toString()).append("\r"); visit(root, 1, buffer); return buffer.toString(); }
From source file:Main.java
public static ThreadGroup rootThreadGroup() { ThreadGroup tg = Thread.currentThread().getThreadGroup(); ThreadGroup ptg = tg.getParent(); while (ptg != null) { tg = ptg;//from ww w.j a va 2s . com ptg = tg.getParent(); } return tg; }