Java examples for java.lang:Thread
Get thread group by name
//package com.java2s; public class Main { /**/*w w w . j a v a 2 s . c o m*/ * Get thread group by name * * @param name * @param root * @return thread group or null */ private static ThreadGroup getThreadGroupByName(String name, ThreadGroup root) { if (root == null) { root = getRootThreadGroup(); } int num_groups = root.activeGroupCount(); ThreadGroup[] groups = new ThreadGroup[num_groups]; root.enumerate(groups, false); for (int i = 0; i < num_groups; i++) { ThreadGroup threadGroup = groups[i]; if (name.equals(threadGroup.getName())) { return threadGroup; } else { threadGroup = getThreadGroupByName(name, threadGroup); if (threadGroup != null) { return threadGroup; } } } return null; } /** * 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; } }