Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Essential Java Virtual Machine Command-Line Utilities

Tech May 7 4

The Java Virtual Machine (JVM) provides several command-line tools for monitoring and debugging applications. These utilities offer insights into process status, runtime statistics, configuration, memory usage, and thread states.

jps: Process Status Tool

This tool lists JVM processes on the local machine. The -l option displays the full package name of the main class.

jps -l

Example output:

14224 org.jetbrains.jps.cmdline.Launcher
8528 org.jetbrains.idea.maven.server.RemoteMavenServer
236 com.example.MainApplication

jstat: Runtime Statistics Monitor

Use jstat to collect data on class loading, garbage collection, memory pools, and JIT compilation. The basic syntax is:

jstat [options] process_id [interval [count]]

To monitor garbage collection for process 236 every 250 milliseconds for 20 iterations:

jstat -gc 236 250 20

jinfo: Configuration Inspector

This utility prints JVM system properties and command-line flags for a specified process.

jinfo 236

Sample output includes Java version, system properties, and non-default VM flags like -XX:InitialHeapSize and -XX:+UseParallelGC.

jmap: Memory Map Analyzer

jmap generates heap dumps and displays memory usage details. Too show heap configuration and usage:

jmap -heap 236

The output breaks down heap regions (Eden, Survivor, Old Generation) with capacities and utilization percentages.

jstack: Thread Stack Trace Tool

For diagnosing deadlocks or high CPU usage, jstack captures thread dumps, showing each thread's stack trace.

jstack 236

Additional Tools

  • jhat: Analyzes heap dump files (.hprof).
  • hsdis: A library for disassembling JIT-compiled native code.

JConsole: Graphical Monitoring

Launch jconsole from the JDK's bin directory to connect to local or remote JVM processes. The interface provides real-time views of memory consumption, thread activity, class counts, and MBean attributes.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.