What is the Thread.dumpStack() function in Java?
Thread.dumpStack() is a static method in Java used to debug the faulty code. This function prints the stack trace of a recent thread to the standard error stream.
Syntax
static void dumpStack()
Return value
No value is returned by this function.
Example
The code below shows the use of dumpStack().
// Load Thread classimport java.lang.Thread*;// Main classpublic class EdPresso {// main methodpublic static void main(String[] args) {Thread thread = Thread.currentThread();th.setName("Main Thread");// setting the priority of thread to 1thread.setPriority(1);// printing the recent threadSystem.out.println("Thread = " + thread);int threadCount = Thread.activeCount();System.out.println("The threads that are active currently = " + threadCount);/* printing current thread's stack trace to the standarderror stream used to debug*/Thread.dumpStack();}}