List of usage examples for java.lang Thread getName
public final String getName()
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 ww. ja v a 2 s .c om*/ } 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"; }
From source file:com.exzogeni.dk.log.formatter.SimpleLogFormatter.java
private static StringBuilder newMessageBuilder(Thread thread, StackTraceElement caller) { return new StringBuilder(256).append("[").append(thread.getName()).append("]").append(" ").append(caller) .append(" >>>>>\n"); }
From source file:ThreadLister.java
/** Display information about a thread. */ private static void printThreadInfo(PrintWriter out, Thread t, String indent) { if (t == null) return;// w w w . j a v a 2s. c om out.println(indent + "Thread: " + t.getName() + " Priority: " + t.getPriority() + (t.isDaemon() ? " Daemon" : "") + (t.isAlive() ? "" : " Not Alive")); }
From source file:Main.java
/** * Display information about a thread.//from w ww . j av a 2 s. c om */ private static void printThreadInfo(PrintWriter out, Thread t, String indent) { if (t == null) { return; } out.println(indent + "Thread: " + t.getName() + " Priority: " + t.getPriority() + (t.isDaemon() ? " Daemon" : "") + (t.isAlive() ? "" : " Not Alive")); }
From source file:Main.java
/** * Print a stack trace of the current thread. *//*from w ww. j a v a 2s.co 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
/** * Print diagnostic info about the current thread. *//*from ww w. j ava2s. c o m*/ 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 Thread getThreadByName(String name) { ThreadGroup tg = Thread.currentThread().getThreadGroup(); while (tg.getParent() != null) { tg = tg.getParent();/* www. j ava 2 s. c om*/ } 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:com.lightbox.android.bitmap.BitmapFileCleanerTask.java
private static ExecutorService getExecutor() { if (sBitmapFileCleanerExecutor == null) { sBitmapFileCleanerExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override// w ww.j a va 2s.c o m public Thread newThread(Runnable r) { Thread thread = new Thread(r); thread.setName(TAG + " | " + thread.getName()); thread.setPriority(Thread.MIN_PRIORITY); return thread; } }); } return sBitmapFileCleanerExecutor; }
From source file:Main.java
public static void startThreadStatusTimer(final Thread t1) { new Timer().schedule(new TimerTask() { @Override// w w w.j a va2s . c o m public void run() { System.out.println("\t\t\t\t\t\t\t\t\t\tThread(" + t1.getName() + ") state - " + t1.getState()); } }, 0, 1000); }
From source file:Main.java
/** Collect info about a thread */ private static void collectThreadInfo(final Thread t, final StringBuffer str, final String indent) { if (t == null) { return;/*from w w w . ja va2 s. c o m*/ } str.append(indent).append("Thread: [").append(t.getName()).append("] Priority: [").append(t.getPriority()) .append(t.isDaemon() ? " Daemon" : "").append("] ").append(t.isAlive() ? "" : " Not Alive") .append(LINE_SEPARATOR); }