List of usage examples for java.lang Thread isDaemon
public final boolean isDaemon()
From source file:Daemon.java
public static void main(String[] args) throws Exception { Thread d = new Daemon(); System.out.println("d.isDaemon() = " + d.isDaemon()); // Allow the daemon threads to // finish their startup processes: Thread.sleep(1000);/* w w w .j a v a 2s.co m*/ }
From source file:Main.java
public static void dumpThreads() { final Map<Thread, StackTraceElement[]> threads = Thread.getAllStackTraces(); for (Thread thread : threads.keySet()) System.out.println((thread.isDaemon() ? "DAEMON " : " ") + thread.getName()); // final ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false); // for(ThreadInfo thread : threads) { // System.out.println(thread.getThreadName() + ": "); // }//from w w w . j a va 2 s. c o m }
From source file:Main.java
public static ThreadFactory createThreadFactory(final String prefix) { return new ThreadFactory() { private AtomicInteger size = new AtomicInteger(); public Thread newThread(Runnable r) { Thread thread = new Thread(r); thread.setName(prefix + size.incrementAndGet()); if (thread.isDaemon()) { thread.setDaemon(false); }/*w ww . ja v a2s . co m*/ return thread; } }; }
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 ww.jav a 2 s . c o 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:ThreadLister.java
private static void printThreadInfo(Thread t, String indent) { if (t == null) return;/*from w w w . ja v a 2 s. c o m*/ System.out.println(indent + "Thread: " + t.getName() + " Priority: " + t.getPriority() + (t.isDaemon() ? " Daemon" : "") + (t.isAlive() ? "" : " Not Alive")); }
From source file:Main.java
public static void dumpAllThreadStacks() { System.out.println("stack trace"); Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces(); for (Thread t : map.keySet()) { StackTraceElement[] elements = map.get(t); System.out.println(t);//from ww w .j a v a2 s .c om System.out.println("isDaemon : " + t.isDaemon() + ", isAlive : " + t.isAlive() + ", isInterrupted : " + t.isInterrupted()); for (StackTraceElement e : elements) { System.out.println("\t" + e); } System.out.println(""); } }
From source file:Main.java
/** * Print a stack trace of the current thread. */// w w w. j a v a 2 s .com 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:ThreadLister.java
/** Display information about a thread. */ private static void printThreadInfo(PrintWriter out, Thread t, String indent) { if (t == null) return;//from w w w .j a v a2 s . com out.println(indent + "Thread: " + t.getName() + " Priority: " + t.getPriority() + (t.isDaemon() ? " Daemon" : "") + (t.isAlive() ? "" : " Not Alive")); }
From source file:Main.java
/** * Print diagnostic info about the current thread. *//*from w ww . j a va 2s . 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
/** * Display information about a thread.// w w w. j ava 2 s . com */ 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")); }