List of usage examples for java.lang Thread isAlive
public final native boolean isAlive();
From source file:Main.java
public static Thread getThreadByName(String name) { ThreadGroup tg = Thread.currentThread().getThreadGroup(); while (tg.getParent() != null) { tg = tg.getParent();/* w w w . ja va 2s.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:Main.java
public static boolean join(Thread thread, long milliseconds) { try {/*from w w w. j av a 2 s . c o m*/ thread.join(milliseconds); } catch (InterruptedException exception) { return false; } if (thread.isAlive()) { thread.interrupt(); return false; } return true; }
From source file:ThreadLister.java
private static void printThreadInfo(Thread t, String indent) { if (t == null) return;//w ww . java 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:org.sonar.process.ProcessUtils.java
public static void awaitTermination(@Nullable Thread t) { if (t == null || Thread.currentThread() == t) { return;/*from w ww.ja va 2 s. com*/ } while (t.isAlive()) { try { t.join(); } catch (InterruptedException e) { // ignore, keep on waiting for t to stop } } }
From source file:com.adaptris.transport.JunitSocketServer.java
private static void join(Thread t) { try {/*from w w w.ja va2s .co m*/ if (t.isAlive()) { t.join(); } } catch (InterruptedException ignored) { logR.warn("Interrupted"); } }
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 w w w. j a va 2 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:org.apache.hadoop.corona.Utilities.java
/** * A realiable way to wait for the thread termination * @param thread thread to wait for/* w w w.ja v a 2 s .c o m*/ */ public static void waitThreadTermination(Thread thread) { while (thread != null && thread.isAlive()) { thread.interrupt(); try { thread.join(); } catch (InterruptedException 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 www. j a va2 s . c o m 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.// w w w . 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:org.trafodion.rest.ResourceChecker.java
/** * Helper function: print the threads/*from w w w.j a v a 2 s. c o m*/ */ public static void printThreads() { Set<Thread> threads = Thread.getAllStackTraces().keySet(); System.out.println("name; state; isDameon; isAlive; isInterrupted"); for (Thread t : threads) { System.out.println(t.getName() + ";" + t.getState() + ";" + t.isDaemon() + ";" + t.isAlive() + ";" + t.isInterrupted()); } }