Example usage for java.lang Thread getStackTrace

List of usage examples for java.lang Thread getStackTrace

Introduction

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

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Returns an array of stack trace elements representing the stack dump of this thread.

Usage

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];
    System.out.println(e.getMethodName());
}

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];

    System.out.println(e.hashCode());
}

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];
    System.out.print("class name : ");
    System.out.print(e.getClassName());
}

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];
    System.out.print("file name : ");
    System.out.print(e.getFileName());
}

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];

    Object ob = "a";
    System.out.println(e.equals(ob));
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];
    System.out.println(e.toString());

}

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];

    System.out.print("line number : ");
    System.out.print(e.getLineNumber());
}

From source file:Main.java

public static void main(String[] args) {

    System.out.println("Is Native method ? :");

    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];

    System.out.println(e.isNativeMethod());

}

From source file:Main.java

public static String getThreadStack(Thread t) {
    StackTraceElement[] stacks = t.getStackTrace();
    StringBuffer buffer = new StringBuffer();
    for (StackTraceElement stack : stacks) {
        String filename = stack.getFileName();
        if (filename == null) {
            filename = "NULL";
        }/*from w  w  w.j av  a 2s . co m*/
        String className = stack.getClassName();
        String methodName = stack.getMethodName();
        int line = stack.getLineNumber();
        buffer.append(String.format("%s.%s(%s:%d)\r", className, methodName, filename, line));
    }
    return buffer.toString();
}

From source file:Main.java

/**
 * Prints the current thread's details to the console.
 *///from   w  ww  . j  av a 2 s .c  om
public static void printCurrentThreadDetails() {

    Thread currentThread = Thread.currentThread();

    StackTraceElement[] stackTrace = currentThread.getStackTrace();

    for (StackTraceElement element : stackTrace) {

        System.out.println("\t" + element);
    }
}