Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is the Thread.dumpStack() function in Java?

Fouzia Bashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 class
import java.lang.Thread*;
// Main class
public class EdPresso {
   // main method
   public static void main(String[] args) {
      Thread thread = Thread.currentThread();
      th.setName("Main Thread");
      // setting the priority of thread to 1
      thread.setPriority(1);
      // printing the recent thread
      System.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 standard
         error stream used to debug*/
      Thread.dumpStack();
   }
}

RELATED TAGS

java
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring