This tutorial demonstrates how to dump stack track of the current thread in Java, this is very useful troubleshoot or debug skill to identify the states of current running thread.

Use Thread.currentThread().getStackTrace() to retrieve an array of StackTraceElements that represent the current stack trace .

This is the example code:
public class TestDumpThread {
        //Dump the current thread stack trace.
        public static void dumpCurrentStackTrace() {
                StackTraceElement[] stes = Thread.currentThread().getStackTrace();
                for (StackTraceElement element : stes) {

        public static void main(String[] args) {

I executed this program and the output was:

java.lang.Thread.getStackTrace(Unknown Source)