List of usage examples for java.lang ThreadGroup getParent
public final ThreadGroup getParent()
From source file:Main.java
public static ThreadGroup getRootThreadGroup() { if (rootThreadGroup == null) { ThreadGroup tg = Thread.currentThread().getThreadGroup(); ThreadGroup parent = tg.getParent(); while (parent != null) { tg = parent;/*from ww w.jav a2 s .c o m*/ parent = tg.getParent(); } rootThreadGroup = tg; } return rootThreadGroup; }
From source file:Main.java
public static Thread[] getThreads() { Thread currentThread = Thread.currentThread(); ThreadGroup threadGroup = currentThread.getThreadGroup(); while (threadGroup.getParent() != null) { threadGroup = threadGroup.getParent(); }/* ww w . j a va 2 s. c o m*/ int threadCountGuess = threadGroup.activeCount(); Thread[] threads = new Thread[threadCountGuess]; int threadCountActual = threadGroup.enumerate(threads); while (threadCountActual == threadCountGuess) { threadCountGuess *= 2; threads = new Thread[threadCountGuess]; threadCountActual = threadGroup.enumerate(threads); } return threads; }
From source file:Main.java
public static ThreadGroup getRootThreadGroup() { ThreadGroup rootThreadGroup = Thread.currentThread().getThreadGroup(); ThreadGroup parent;/*w ww . ja v a2s . c o m*/ while ((parent = rootThreadGroup.getParent()) != null) { rootThreadGroup = parent; } return rootThreadGroup; }
From source file:Main.java
public static Thread getThreadByName(String name) { ThreadGroup tg = Thread.currentThread().getThreadGroup(); while (tg.getParent() != null) { tg = tg.getParent();/*from w w w.j av a 2 s . co m*/ } Thread[] threads = new Thread[tg.activeCount() + 1024]; tg.enumerate(threads, true); boolean bad_found = false; for (int i = 0; i < threads.length; i++) { Thread t = threads[i]; if (t != null && t.isAlive() && t != Thread.currentThread() && !t.isDaemon() && t.getName().equals(name)) { return t; } } return null; }
From source file:Main.java
/** * Returns the root thread group./*from w w w.j ava2s . c o m*/ * * @return The root thread group. */ public static ThreadGroup getRootThreadGroup() { ThreadGroup group = getCurrentThread().getThreadGroup(); ThreadGroup parent = group.getParent(); while (parent != null) { group = parent; parent = group.getParent(); } return group; }
From source file:Main.java
public static List<Thread> getFullThreadList(boolean includeDaemons) { List<Thread> list = new ArrayList<Thread>(); // Find the root thread group ThreadGroup root = Thread.currentThread().getThreadGroup().getParent(); while (root.getParent() != null) { root = root.getParent();/*from w ww . ja v a2 s . c o m*/ } // Visit each thread group visit(list, root, 0, includeDaemons); // returns the full list return list; }
From source file:Main.java
private static ThreadGroup getRootThreadGroup() { if (ROOT == null) { ThreadGroup current = Thread.currentThread().getThreadGroup(); ThreadGroup parent;// ww w .j a va2 s. c o m while ((parent = current.getParent()) != null) current = parent; ROOT = current; } return ROOT; }
From source file:Main.java
public static ThreadGroup getRootThreadGroup() { if (rootThreadGroup != null) { return rootThreadGroup; }/*from ww w . j a va 2 s . co m*/ ThreadGroup tg = Thread.currentThread().getThreadGroup(); ThreadGroup ptg; while ((ptg = tg.getParent()) != null) { tg = ptg; } return tg; }
From source file:Main.java
public static ArrayList<Thread> getThreads() { // Find the root thread group ThreadGroup root = Thread.currentThread().getThreadGroup().getParent(); while (root.getParent() != null) { root = root.getParent();// w ww . j ava 2s.co m } ArrayList<Thread> threads = new ArrayList<Thread>(); visit(root, 0, threads); return threads; }
From source file:Main.java
/** * Get root thread group/* w w w .j av a2 s.c o m*/ * * @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; }