Java, Maven and Gradle 25 cheatsheet

Java, Maven and Gradle 25: Diagnostics

6 common Java, Maven and Gradle 25 tasks.

List running Java processes

Show Java process IDs with their main class or jar.

jps -l

Take a thread dump

Print every thread's stack. Useful for hangs and deadlocks.

jcmd 12345 Thread.print

Show heap usage

Print a summary of the heap.

jcmd 12345 GC.heap_info

Write a heap dump

Save the heap to a file to analyze memory leaks.

jcmd 12345 GC.heap_dump /tmp/heap.hprof

Caution: A heap dump can be as large as the heap and may contain sensitive data.

Dump the heap on OutOfMemoryError

Have the JVM write a heap dump automatically when memory runs out.

java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -jar app.jar

Show the flags a JVM is using

Print the JVM flags of a running process.

jcmd 12345 VM.flags

Was this page helpful?