The jstack command of the java virtual machine

1. Concept

       Used to generate a thread snapshot of the java virtual machine at the current moment. Thread snapshot is a collection of method stacks being executed by each thread in the current java virtual machine. The main purpose of generating thread snapshots is to locate the cause of long pauses in threads, such as deadlocks between threads, infinite loops, and long caused by external resources Time to wait and wait. When a thread is stalled, you can view the call stack of each thread through jstack, and you can know what the unresponsive thread is doing in the background, or what resources it is waiting for. If the java program crashes to generate a core file, the jstack tool can be used to obtain the java stack and native stack information of the core file, so that you can easily know how the java program crashed and where the problem occurred. In addition, the jstack tool can also be attached to the running java program, and you can see the java stack and native stack information of the running java program at the time. If the currently running java program shows a hung state, jstack is very useful.

2. Grammar

         jstack [ option ] pid

         jstack [ option ] executable core

        jstack [ option ] [server-id@]remote-hostname-or-IP

Common parameter description

1)、options: 

      executable Java executable from which the core dump was produced.

     core core dump file of the information to be printed

    remote-hostname-or-IP hostname or ip of remote debug service

     server-id unique id, if multiple remote debug services on a host 

2) Basic parameters:

    -F Force to print stack information when'jstack [-l] pid' has no corresponding

    -l Long list. Print additional information about locks, such as the list of ownable synchronizers belonging to java.util.concurrent.

    -m Print all stack information of java and native c/c++ frameworks.

    -h | -help print help information

    pid The id of the java process whose configuration information needs to be printed, can be queried with jps.

Three, example

1. Output the stack information of the current process: jstack -l 2626

2626 is the pid, which can be obtained through ps -ef|grep java or jps -ml

2. Output the current process to the file: jstack -l 2626 >> test.log

The stack of the process can be output to the log, and then downloaded to the local for troubleshooting.

 

Scenario: JVM tuning, especially in viewing problems such as blocking and deadlock

 

Study address:

https://www.cnblogs.com/taiguyiba/p/9470861.html

https://blog.csdn.net/fenglibing/article/details/6411940

 

Guess you like

Origin blog.csdn.net/baidu_28068985/article/details/108176278