jstack is a command that comes with the JDK. If you have a machine running java, you can easily get the process status without installing a special monitoring tool.
This tool displays a thread dump on the command line console. You can use it if you know the Java PID. You can use this tool to get the thread status and use it for investigation when performance is poor or when a phenomenon such as deadlock occurs.
Usage
$ jstack -l <pid>
You can check the stack trace for each thread in the output result.
"Thread-0" #12 prio=5 os_prio=0 cpu=0.00ms elapsed=496.25s tid=0x00007f6a741f1800 nid=0x1a5 waiting on condition [0x00007f6a17a9f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep([email protected]/Native Method)
at Server.sleepForever(Server.java:20)
at Server.lambda$0(Server.java:9)
at Server$$Lambda$1/0x0000000840060840.run(Unknown Source)
at java.lang.Thread.run([email protected]/Thread.java:834)
"Thread-1" #13 prio=5 os_prio=0 cpu=0.00ms elapsed=496.25s tid=0x00007f6a741f3800 nid=0x1a6 waiting on condition [0x00007f6a1798f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep([email protected]/Native Method)
at Server.sleepForever(Server.java:20)
at Server.lambda$0(Server.java:9)
at Server$$Lambda$1/0x0000000840060840.run(Unknown Source)
at java.lang.Thread.run([email protected]/Thread.java:834)
"Thread-2" #14 prio=5 os_prio=0 cpu=0.00ms elapsed=496.25s tid=0x00007f6a741f5000 nid=0x1a7 waiting on condition [0x00007f6a1787f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep([email protected]/Native Method)
at Server.sleepForever(Server.java:20)
at Server.lambda$0(Server.java:9)
at Server$$Lambda$1/0x0000000840060840.run(Unknown Source)
at java.lang.Thread.run([email protected]/Thread.java:834)
For example, in the case where java is running in multiple threads, if some thread is eating a lot of CPU usage or memory, it can be specified as follows.
(1) Identify the process that is consuming resources from the process.
$ top -H -b -n 1 -p ${java pid}
Get the resource-consuming PID from the above command
(2) Convert PID to hexadecimal number and grep from the result of jstack ③ Since the trace that matches nid and hexadecimal number is a resource-consuming process, follow it from there.
It is possible to investigate in such a flow.
Recommended Posts