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 String getCallerNoPackageClassNameMethod() {
    final StackTraceElement el = Thread.currentThread().getStackTrace()[2];
    final String noPackageClassName = el.getClassName().replaceAll(".*\\.", "");
    final String methodName = el.getMethodName();
    final String retval = noPackageClassName + "." + methodName;
    return retval;

}

From source file:Main.java

public static boolean isOnUIThread() {
    Thread currentThread = Thread.currentThread();
    return currentThread == sUIThread;
}

From source file:Main.java

public static boolean isEventSidpathThread() {
    return Thread.currentThread() == swingThread;
}

From source file:Main.java

public static void showThreadName() {
    String groupName = Thread.currentThread().getThreadGroup().getName();
    String threadName = Thread.currentThread().getName();
    System.out.println(String.format("%s-%s", groupName, threadName));
}

From source file:Main.java

public static void sleep(long millis) {
    try {//from  w  w w . j  a  va 2s . com
        Thread.currentThread().sleep(millis);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

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

From source file:Main.java

public static final void log(String message) {
    StackTraceElement ste = Thread.currentThread().getStackTrace()[3];
    String className = ste.getClassName();
    className = className.substring(className.lastIndexOf(".") + 1);
    String methodName = ste.getMethodName();
    int lineNum = ste.getLineNumber();
    String logText = String.format("%s(%s):%s", methodName, lineNum, message);
    Log.d(className, logText);//from   w  ww.  j  av  a2s  .  c  o  m
}

From source file:Main.java

public static String stackTrace() {
    StackTraceElement[] elements = Thread.currentThread().getStackTrace();
    StringBuilder buf = new StringBuilder();
    for (int i = 0; i < elements.length; i++) {
        buf.append("\r\n   ").append(elements[i].getClassName()).append(".").append(elements[i].getMethodName())
                .append("(").append(elements[i].getFileName()).append(":").append(elements[i].getLineNumber())
                .append(")");
    }/*from  www. ja  v  a 2s  .c o m*/
    return buf.toString();
}

From source file:Main.java

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

From source file:Main.java

public static String getMethodName() {
    final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
    return ste[2].getMethodName();
}