List of usage examples for java.lang ThreadGroup getName
public final String getName()
From source file:Main.java
public static void main(String[] args) { ThreadGroup group = new ThreadGroup("admin"); Thread t = new Thread(group, "website"); System.out.println("Threadgroup = " + group.getName()); String str = group.toString(); System.out.println(str);//from www. j a va 2 s. c o m }
From source file:Main.java
public static void main(String[] args) { Thread t1 = Thread.currentThread(); ThreadGroup tg1 = t1.getThreadGroup(); System.out.println("Current thread's name: " + t1.getName()); System.out.println("Current thread's group name: " + tg1.getName()); Thread t2 = new Thread("my new thread"); ThreadGroup tg2 = t2.getThreadGroup(); System.out.println("New thread's name: " + t2.getName()); System.out.println("New thread's group name: " + tg2.getName()); }
From source file:Main.java
private static String getThreadGroupName(Thread thread) { ThreadGroup threadGroup = thread.getThreadGroup(); return (threadGroup == null) ? "stopped" : threadGroup.getName(); }
From source file:Main.java
public static ThreadGroup getThreadGroupByName(String name) { if (name != null) { final ThreadGroup[] groups = getAllThreadGroups(); for (ThreadGroup group : groups) { if (group.getName().equals(name)) { return group; }// w w w. jav a 2s.c o m } } return null; }
From source file:Main.java
/** * Get the thread group with the given name. A null is returned if no such * group is found. If more than one group has the same name, the first one * found is returned./* ww w.j a va 2s . co m*/ * * @param name * the thread group name to search for * @return the thread group, or null if not found * @throws NullPointerException * if the name is null */ public static ThreadGroup getThreadGroup(final String name) { if (name == null) { throw new NullPointerException("Null name"); } final ThreadGroup[] groups = getAllThreadGroups(); for (ThreadGroup group : groups) { if (group.getName().equals(name)) return group; } return null; }
From source file:Main.java
/** * Get thread group by name/*from w w w.j a v a 2 s . c om*/ * * @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; }
From source file:Main.java
/** * Print a stack trace of the current thread. *//*from www . ja v a 2 s. c o m*/ public static void printFullStackTrace() { Thread thread = Thread.currentThread(); System.out.printf(" Thread id: %d, name: %s, state: %s, daemon: %s, EDT: %s\n", thread.getId(), thread.getName(), thread.getState(), thread.isDaemon(), EventQueue.isDispatchThread()); ThreadGroup group = thread.getThreadGroup(); System.out.printf(" priority: %d, group: %s, group count: %d\n", thread.getPriority(), group.getName(), group.activeCount()); StackTraceElement[] backtrace = thread.getStackTrace(); for (StackTraceElement e : backtrace) { System.out.printf(" Stack Trace: %s\n", e); } }
From source file:Main.java
/** * Get the thread group with the given name. A null is * returned if no such group is found. If more than one * group has the same name, the first one found is returned. * * @param name the thread group name to search for * @return the thread group, or null if not found * @throws NullPointerException/*from w w w.j a v a 2 s. c o m*/ * if the name is null */ public static ThreadGroup getThreadGroup(final String name) { if (name == null) throw new NullPointerException("Null name"); final ThreadGroup[] groups = getAllThreadGroups(); for (ThreadGroup group : groups) if (group.getName().equals(name)) return group; return null; }
From source file:Main.java
/** * Print diagnostic info about the current thread. *///from w w w . j a v a2s. com public static void printThreadInfo() { Thread thread = Thread.currentThread(); System.out.printf(" Thread id: %d, name: %s, state: %s, daemon: %s, EDT: %s\n", thread.getId(), thread.getName(), thread.getState(), thread.isDaemon(), EventQueue.isDispatchThread()); ThreadGroup group = thread.getThreadGroup(); System.out.printf(" priority: %d, group: %s, group count: %d\n", thread.getPriority(), group.getName(), group.activeCount()); StackTraceElement[] backtrace = thread.getStackTrace(); if (backtrace.length > 2) { System.out.printf(" trace[2]: %s\n", backtrace[2]); } }
From source file:Main.java
public static String dumpThreads() { StringBuilder sb = new StringBuilder("\n"); ThreadGroup tg, parent = Thread.currentThread().getThreadGroup(); while ((tg = parent.getParent()) != null) { parent = tg;//from w w w . j a va2 s.c o m } int size = 2 * parent.activeGroupCount(); ThreadGroup[] list = new ThreadGroup[size]; int actual = parent.enumerate(list, true); //System.out.print("found " + list); sb.append("tgs: " + actual + "\n"); if (list != null && list.length > 0) { for (ThreadGroup g : list) { if (g == null) { continue; } sb.append(" " + g.getName() + ": " + g.activeCount() + "\n"); Thread[] threads = new Thread[g.activeCount()]; g.enumerate(threads, false); for (Thread t : threads) { if (t != null) { sb.append(" " + t.getName() + "\n"); } } } } else { System.out.println("empty thread group list"); } return sb.toString() + "\n"; }