dumpstack_Java Thread类的静态void dumpStack()方法(带示例)
dumpstack
線程類靜態(tài)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).
此方法用于打印或顯示當(dāng)前線程到System.err (標(biāo)準(zhǔn)錯(cuò)誤流)的堆棧跟蹤。
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).
該方法的目的基本上是用于調(diào)試(即,如果我們調(diào)用多個(gè)方法,那么很難發(fā)現(xiàn)錯(cuò)誤,因此借助該方法,我們可以在堆棧跟蹤或堆棧層次結(jié)構(gòu)中找到錯(cuò)誤)。
This method is static so this method is accessible with classname too like Thread.dumpStack().
此方法是靜態(tài)的,因此也可以使用類名訪問(wèn)此方法,例如Thread.dumpStack() 。
The return type of this method is void it does not return anything.
此方法的返回類型為void,它不返回任何內(nèi)容。
This method does not raise any exception.
此方法不會(huì)引發(fā)任何異常。
Syntax:
句法:
static void dumpStack(){}Parameter(s):
參數(shù):
We don't pass any object as a parameter in the method of the File.
我們不會(huì)在File方法中將任何對(duì)象作為參數(shù)傳遞。
Return value:
返回值:
The return type of this method is void, it does not return anything.
此方法的返回類型為void ,它不返回任何內(nèi)容。
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
總結(jié)
以上是生活随笔為你收集整理的dumpstack_Java Thread类的静态void dumpStack()方法(带示例)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 图文并茂的聊聊Java内存模型!
- 下一篇: 人工智能ai 学习_人工智能中强化学习的