dumpStack() मेथड Thread क्लास का एक स्टैटिक मेथड है और इसका उपयोग वर्तमान थ्रेड के स्टैक ट्रेस को System.err पर प्रिंट या प्रदर्शित करने के लिए किया जा सकता है। dumpStack() मेथड का उद्देश्य मूल रूप से डीबगिंग के लिए है और आंतरिक रूप से यह मेथड Throwable क्लास के printStackTrace() मेथड को कॉल करता है। यह मेथड कोई अपवाद नहीं उठाता।
सिंटैक्स
public static void dumpStack()
उदाहरण
public class ThreadDumpStackTest { public static void main(String args[]) { Thread t = Thread.currentThread(); t.setName("ThreadDumpStackTest"); t.setPriority(1); System.out.println("Current Thread: " + t); int count = Thread.activeCount(); System.out.println("Active threads: " + count); Thread threads[] = new Thread[count]; Thread.enumerate(threads); for (int i = 0; i < count; i++) { System.out.println(i + ": " + threads[i]); } Thread.dumpStack(); } }आउटपुट
Current Thread: Thread[ThreadDumpStackTest,1,main] Active threads: 1 0: Thread[ThreadDumpStackTest,1,main] java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Thread.java:1336) at ThreadDumpStackTest.main(ThreadDumpStackTest.java:14)