dumpStack() 메소드는 정적 메소드입니다. 스레드 의 클래스 현재 스레드의 스택 추적을 System.err에 인쇄하거나 표시하는 데 사용할 수 있습니다. . dumpStack()의 목적 메소드는 기본적으로 디버깅용입니다. 내부적으로 이 메소드는 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)