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)
以上是在Java中使用dumpStack()方法的目的是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!