Check the status of Java application without using monitoring tool

Overview

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

Check the status of Java application without using monitoring tool
Status monitoring of java application using Elasticsearch
Check the rate limit application status of docker pull
Command to check the number and status of Java threads
Check the migration status of rails
Check the contents of the Java certificate store
[Java] Check the number of occurrences of characters
Java 9+ application status
[Java] Check the JDK version of the built war file
Check the behavior of Java Intrinsic Locks with bpftrace
Check the operation of two roles with a chat application
[Java] Try editing the elements of the Json string using the library
The story of pushing Java to Heroku using the BitBucket pipeline
I tried using the cache function of Application Container Cloud Service
Try using the two-point measurement function of Firebase Performance Monitoring. [Android]
[Swift UI] How to get the startup status of the application [iOS]
Let's create a TODO application in Java 5 Switch the display of TODO
How to check for the contents of a java fixed-length string
Is the version of Elasticsearch you are using compatible with Java 11?
[Java] Delete the elements of List
[Rails] Check the contents of the object
[Java version] The story of serialization
Check the version of Cent OS
Java comparison using the compareTo () method
Handling of time zones using Java
Summary of object-oriented programming using Java
The origin of Java lambda expressions
I tried using GoogleHttpClient of Java
Parse and objectize JSON using the @JsonProperty annotation of the Java library Jackson
[Java] How to get to the front of a specific string using the String class
Check the domain by checking the MX record of the email address with java
[Java] Check if the character string is composed only of blanks (= Blank)
Display Japanese calendar and days of the week using java8 standard class
Check the flag after a certain amount of time has passed since the thread started running without using the Timer thread.
[Java] Express Enum type without using Enum (enumeration) type
Try using Java framework Nablarch [Web application]
Check the operation using jetty with Maven.
Get the result of POST in Java
Try using || instead of the ternary operator
Check the contents of params with pry
Examine the memory usage of Java elements
[Java] Get the day of the specific day of the week
Newcomer training using the Web-Basic programming using Java-
Test the integrity of the aggregation using ArchUnit ②
Map without using an array in java
ERRORCODE = -4471 occurs in Java application using Db2.
Compare the elements of an array (Java)
[day: 5] I summarized the basics of Java
What are the updated features of java 13
Easily measure the size of Java Objects
Looking back on the basics of Java
Output of the book "Introduction to Java"
Memory measurement of Java application on Windows
Acquisition of input contents using Scanner (Java)
The story of writing Java in Emacs
Check the version of the standard Web software.
[Java] [Spring] Test the behavior of the logger
Role of JSP in Web application [Java]
Try using the Wii remote with Java
Check the operation of the interface through threads
Test the integrity of the aggregation using ArchUnit ③