Thread dumpStack() method in Java

Method declaration – public static void dumpStack().

This method is used only for debugging purpose. Internally this method is calling printStackTrace() method only.

    public static void dumpStack() {
        new Exception("Stack trace").printStackTrace();
    }

This method will always throw an exception.

package multithreading;

public class ThreadDumpStackExample {
	public static void main(String[] args) {
		Thread.currentThread().dumpStack();
	}
}

Output is –

java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Unknown Source)
at multithreading.ThreadDumpStackExample.main(ThreadDumpStackExample.java:5)