線程類的 dumpStack() 方法將當前線程的堆棧跟蹤打印到標準錯誤流。它僅用於調試。
用法
public static void dumpStack()
返回
此方法不返回任何值。
示例
public class JavaDumpStackExp
{
public static void main(String[] args)
{
Thread thread = Thread.currentThread();
thread.setName("My ThreadDumpStack");
// set thread priority to 6
thread.setPriority(6);
// prints the current thread
System.out.println("Current thread:" + thread);
int count = Thread.activeCount();
System.out.println("currently active threads:" + count);
// prints a stack trace of the current thread to the standard error stream, used for debugging
Thread.dumpStack();
}
}
輸出:
Current thread:Thread[My ThreadDumpStack,6,main] currently active threads:1 java.lang.Exception:Stack trace at java.lang.Thread.dumpStack(Thread.java:1336) at javatpoint.java.JavaDumpStackExp.main(JavaDumpStackExp.java:19)
相關用法
- Java Thread destroy()用法及代碼示例
- Java Thread toString()用法及代碼示例
- Java Thread interrupted()用法及代碼示例
- Java Thread setDefaultUncaughtExceptionHandler()用法及代碼示例
- Java Thread suspend()用法及代碼示例
- Java Thread holdLock()用法及代碼示例
- Java Thread getContextClassLoader()用法及代碼示例
- Java Thread setContextClassLoader()用法及代碼示例
- Java Thread sleep()用法及代碼示例
- Java Thread getThreadGroup()用法及代碼示例
- Java Thread isInterrupted()用法及代碼示例
- Java Thread enumerate()用法及代碼示例
- Java Thread notify()用法及代碼示例
- Java Thread resume()用法及代碼示例
- Java Thread activeCount()用法及代碼示例
- Java Thread isDaemon()用法及代碼示例
- Java Thread setDaemon()用法及代碼示例
- Java Thread getId()用法及代碼示例
- Java Thread setName()用法及代碼示例
- Java Thread getDefaultUncaughtExceptionHandler()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Thread dumpStack() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。