Common JVM Performance Tuning and Monitoring Tools: jps, jstack, jmap, jstat, hprof
This article explains how to use built‑in JVM tools such as jps, jstack, jmap, jstat and hprof to diagnose memory leaks, OutOfMemoryError, thread deadlocks, lock contention and high CPU usage in enterprise Java applications, providing command syntax, examples and interpretation of output.
In enterprise Java applications, common performance problems such as OutOfMemoryError, memory leaks, thread deadlocks, lock contention, and high CPU usage need systematic diagnosis.
The article introduces several built‑in JVM tools:
1. jps (Java Virtual Machine Process Status Tool)
Shows JVM process IDs and class names. Common options: -q, -m, -l, -v. Example:
jps -m -l 2458 org.artifactory.standalone.main.Main /usr/local/artifactory-2.2.5/etc/jetty.xml
29920 com.sun.tools.hat.Main -port 9998 /tmp/dump.dat
3149 org.apache.catalina.startup.Bootstrap start
30972 sun.tools.jps.Jps -m -l
8247 org.apache.catalina.startup.Bootstrap start
25687 com.sun.tools.hat.Main -port 9999 dump.dat
21711 mrf-center.jar2. jstack
Displays thread stack traces for a given JVM. Options include -l for lock info and -m for mixed mode. Example workflow to locate the most CPU‑intensive thread:
# Find PID
ps -ef | grep mrf-center | grep -v grep
# List threads with CPU time
top -Hp 21711
# Convert thread ID to hex
printf "%x
" 21742
# Show stack for that thread
jstack 21711 | grep 54ee3. jmap and jhat
jmap can dump heap memory or display heap statistics. Typical commands:
jmap -heap 21711
jmap -histo:live 21711 | more
jmap -dump:format=b,file=/tmp/dump.dat 21711The resulting dump can be inspected with jhat, MAT or VisualVM.
4. jstat
Provides real‑time JVM statistics such as GC activity. Example: jstat -gc 21711 250 4 Columns include survivor space usage (S0C, S1C), Eden (EC), old generation (OC), permanent generation (PC), and GC counters (YGC, YGCT, FGC, FGCT, GCT).
5. hprof
Legacy profiling agent that can record CPU sampling, heap allocation, or full heap dumps. Example invocations:
java -agentlib:hprof=cpu=samples,interval=20,depth=3 Hello
javac -J-agentlib:hprof=cpu=times Hello.java
java -agentlib:hprof=heap=sites HelloNote that hprof adds noticeable overhead and is not recommended for production.
Overall, mastering these tools helps Java developers diagnose memory and CPU bottlenecks, understand GC behavior, and improve application stability.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
