dumpStack()方法是一个静态方法 的螺纹 类 ,它可以用于打印或当前线程的显示器层叠跟踪System.err的。 的目的dumpStack()方法基本上用于调试和内部此方法调用的printStackTrace() 的方法的Throwable 类。此方法不会引发任何异常。
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)