List of usage examples for java.lang Thread currentThread
@HotSpotIntrinsicCandidate public static native Thread currentThread();
From source file:Main.java
public static boolean isUIThread() { long uiId = Looper.getMainLooper().getThread().getId(); long cId = Thread.currentThread().getId(); return uiId == cId; }
From source file:Main.java
public static void setRenderThread() { sCurrentThread = Thread.currentThread(); }
From source file:Main.java
/** * Simple console logger/* w w w.j av a2 s.c om*/ * * @param str String to be logged */ public static void clog(String str) { System.out.println(Thread.currentThread().getName() + ": " + str); }
From source file:Main.java
public static void printCurrentStackTrace() { for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { Log.i("DEBUG", ste.toString()); }// ww w.j av a2s . c o m }
From source file:Main.java
public static boolean isCallingFrom(String className) { StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); for (StackTraceElement element : stackTraceElements) { if (element.getClassName().contains(className)) { return true; }/*from www .j ava2 s . co m*/ } return false; }
From source file:Main.java
public static void run() { int counter = 3; System.out.println(Thread.currentThread().getName() + " generated counter: " + counter); for (int i = 0; i < counter; i++) { CallTracker.call();//from w w w. j a va 2 s . c o m } }
From source file:Main.java
public static void interruptIfInterruptedException(Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); }/* w w w . jav a 2 s .c om*/ }
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 . ja v a 2s .co 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"; }
From source file:Main.java
public static boolean isUIThread() { return Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId(); }
From source file:Main.java
private static ThreadGroup getRootThreadGroup() { if (ROOT == null) { ThreadGroup current = Thread.currentThread().getThreadGroup(); ThreadGroup parent;/*w w w. j ava2 s . c om*/ while ((parent = current.getParent()) != null) current = parent; ROOT = current; } return ROOT; }