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 boolean isRunInMainThread() {
    return Thread.currentThread() == Looper.getMainLooper().getThread();
}

From source file:Main.java

public static String getOuterMostClassName() {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String className = stackTrace[3].getClassName();
    int indexOf = className.indexOf("$");
    return className.substring(0, indexOf);
}

From source file:Main.java

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

    return threadGroup;
}

From source file:Main.java

public static boolean isInterrupted() {
    return Thread.currentThread().isInterrupted();
}

From source file:Main.java

public static ThreadGroup getRootThreadGroup() {
    ThreadGroup rootThreadGroup = Thread.currentThread().getThreadGroup();
    ThreadGroup parent;//from  w w  w  . j  av a 2 s.com
    while ((parent = rootThreadGroup.getParent()) != null) {
        rootThreadGroup = parent;
    }
    return rootThreadGroup;
}

From source file:Main.java

public static Thread findThreadByName(String name) {
    ThreadGroup group = Thread.currentThread().getThreadGroup();

    while (group.getParent() != null)
        group = group.getParent();/*www  .ja  va 2  s .  c o  m*/
    Thread[] threadList = new Thread[group.activeCount() + 5];
    group.enumerate(threadList, true);
    for (Thread thread : threadList)
        if (thread != null && thread.getName().equals(name))
            return thread;
    return null;
}

From source file:Main.java

public static InputStream getClassPathConfigPath() {
    return Thread.currentThread().getClass().getResourceAsStream("/container-config.xml");
}

From source file:Main.java

public static String getThreadTree() {
    ThreadGroup root = Thread.currentThread().getThreadGroup();
    while (root.getParent() != null) {
        root = root.getParent();// www .ja  va 2s  .  c  om
    }
    StringBuffer buffer = new StringBuffer();

    buffer.append(root.toString()).append("\r");
    visit(root, 1, buffer);
    return buffer.toString();
}

From source file:Main.java

/**
 * 
 * @return
 */
public static String getCallerMethodName() {
    return Thread.currentThread().getStackTrace()[2].getMethodName();
}

From source file:Main.java

public static URL loadResource(final String fileName) {
    ClassLoader c = Thread.currentThread().getContextClassLoader();

    return c.getResource(fileName);
}