dumpstack_Java Thread类的静态void dumpStack()方法(带示例)
dumpstack
線程類靜態void dumpStack() (Thread Class static void dumpStack())
This method is available in package java.lang.Thread.dumpStack().
軟件包java.lang.Thread.dumpStack()中提供了此方法。
This method is used to print or display stack tracing of the current thread to System.err (Standard error stream).
此方法用于打印或顯示當前線程到System.err (標準錯誤流)的堆棧跟蹤。
The purpose of this method is basically for debugging (i.e. If we call multiple methods so it is difficult to find an error so with the help of this method we can find an error in stack trace or stack hierarchy).
該方法的目的基本上是用于調試(即,如果我們調用多個方法,那么很難發現錯誤,因此借助該方法,我們可以在堆棧跟蹤或堆棧層次結構中找到錯誤)。
This method is static so this method is accessible with classname too like Thread.dumpStack().
此方法是靜態的,因此也可以使用類名訪問此方法,例如Thread.dumpStack() 。
The return type of this method is void it does not return anything.
此方法的返回類型為void,它不返回任何內容。
This method does not raise any exception.
此方法不會引發任何異常。
Syntax:
句法:
static void dumpStack(){}Parameter(s):
參數:
We don't pass any object as a parameter in the method of the File.
我們不會在File方法中將任何對象作為參數傳遞。
Return value:
返回值:
The return type of this method is void, it does not return anything.
此方法的返回類型為void ,它不返回任何內容。
Java程序演示dumpStack()方法的示例 (Java program to demonstrate example of dumpStack() method)
/* We will use Thread class methods so we are importing the package but it is not mandate because it is imported by default */ import java.lang.Thread;public class PrintStackTraceOfCurrentThread {public static void main(String[] args) {// By using currentThread() of Thread class will return a // reference of currently executing thread.Thread th = Thread.currentThread();// By using setName() method we are setting the name // of current executing threadth.setName("Main Thread");// By using setPriority() method we are setting the // priority of current executing threadth.setPriority(2);//Display Current Executing ThreadSystem.out.println("Currently Executing Thread is :" + th);int active_thread = Thread.activeCount();// Display the number of active threads in current threads thread groupSystem.out.println("The Current active threads is : " + active_thread);// Display stack trace of current thread // to the System.err (Standard error stream)Thread.dumpStack();} }Output
輸出量
E:\Programs>javac PrintStackTraceOfCurrentThread.javaE:\Programs>java PrintStackTraceOfCurrentThread Currently Executing Thread is :Thread[Main Thread,2,main] The Current active threads is : 1 java.lang.Exception: Stack traceat java.lang.Thread.dumpStack(Thread.java:1365)at PrintStackTraceOfCurrentThread.main(PrintStackTraceOfCurrentThread.java:24)翻譯自: https://www.includehelp.com/java/thread-class-static-void-dumpstack-method-with-example.aspx
dumpstack
總結
以上是生活随笔為你收集整理的dumpstack_Java Thread类的静态void dumpStack()方法(带示例)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图文并茂的聊聊Java内存模型!
- 下一篇: Java ObjectInputStre