在Java中使用dumpStack()方法的目的是什么?

语法

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();
   }
}

Output

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()方法的目的是什么?的详细内容,更多请关注其它相关文章!