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.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Common JVM Performance Tuning and Monitoring Tools: jps, jstack, jmap, jstat, hprof

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.jar

2. 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 54ee

3. 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 21711

The 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 Hello

Note 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaJVMperformanceProfilingtools
Java Architect Essentials
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.