द डंपस्टैक () विधि एक स्थिर विधि . है थ्रेड . का कक्षा और इसका उपयोग वर्तमान थ्रेड के स्टैक ट्रेसिंग को System.err . पर प्रिंट या प्रदर्शित करने के लिए किया जा सकता है . डंपस्टैक () . का उद्देश्य विधि मूल रूप से डिबगिंग के लिए है और आंतरिक रूप से यह विधि 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)पर