How can I get the current stack trace in Java?

前端 未结 21 3704
耶瑟儿~
耶瑟儿~ 2020-11-21 23:49

How do I get the current stack trace in Java, like how in .NET you can do Environment.StackTrace?

I found Thread.dumpStack() but it is not what I want -

21条回答
  •  没有蜡笔的小新
    2020-11-22 00:34

    You can use jstack utility if you want to check the current call stack of your process.

    Usage:
        jstack [-l] 
            (to connect to running process)
        jstack -F [-m] [-l] 
            (to connect to a hung process)
        jstack [-m] [-l]  
            (to connect to a core file)
        jstack [-m] [-l] [server_id@]
            (to connect to a remote debug server)
    
    Options:
        -F  to force a thread dump. Use when jstack  does not respond (process is hung)
        -m  to print both java and native frames (mixed mode)
        -l  long listing. Prints additional information about locks
        -h or -help to print this help message
    

提交回复
热议问题