Example usage for java.lang Thread currentThread

List of usage examples for java.lang Thread currentThread

Introduction

In this page you can find the example usage for java.lang Thread currentThread.

Prototype

@HotSpotIntrinsicCandidate
public static native Thread currentThread();

Source Link

Document

Returns a reference to the currently executing thread object.

Usage

From source file:Main.java

public static void dumpThreads() {

    ThreadGroup group = Thread.currentThread().getThreadGroup();
    int activeCount = group.activeCount();
    Thread[] threads = new Thread[activeCount];
    group.enumerate(threads);//w  w w  .  j  a  va2 s . c o m

    System.out.println("Thread-Group " + group + " contains " + activeCount + " threads");

    for (Thread thread : threads) {
        System.out.println("Thread " + thread);
    }
}

From source file:Main.java

public static final boolean isOnUiThread() {
    return Looper.getMainLooper().getThread() == Thread.currentThread();
}

From source file:Main.java

public static void interruptCheck() throws InterruptedException {
    if (Thread.currentThread().isInterrupted()) {
        throw new InterruptedException();
    }// w ww .j  a  va  2s. c  o m
}

From source file:Main.java

public static boolean isMainLooperThread() {
    return Looper.getMainLooper().getThread() != Thread.currentThread();
}

From source file:Main.java

public static ThreadGroup getRootThreadGroup() {
    ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
    while (null != threadGroup.getParent()) {
        threadGroup = threadGroup.getParent();
    }/*from w w w  . j  a  va 2  s . c o  m*/

    return threadGroup;
}

From source file:Main.java

public static String getLastClassCall() {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String callingClass = stackTrace[2].getClassName();
    for (int i = 3; i < 3000; i++) {
        String aClass = stackTrace[i].getClassName();
        if (!callingClass.equals(aClass)) {
            return aClass;
        }/*from w w w .ja v a  2  s .c om*/
    }
    return null;
}

From source file:Main.java

private static final boolean currentThreadIsUiThread() {
    return Looper.getMainLooper().getThread() == Thread.currentThread();
}

From source file:Main.java

public static String getThreadInfo() {
    return String.format(Locale.getDefault(), "[thread_id:%d name=%s]", Thread.currentThread().getId(),
            Thread.currentThread().getName());
}

From source file:Main.java

public static boolean isHandlerThread(Handler handler) {
    return Thread.currentThread().equals(handler.getLooper().getThread());
}

From source file:Main.java

public static void waitFor(long millis) {
    try {/*from www .j  av  a  2s . co  m*/
        Thread.sleep(millis);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}