Java Tools Tutorials - Herong's Tutorial Notes - Version 5.32, by Dr. Herong Yang
Connecting Java VisualVM to a Local JVM Process
This section provides a tutorial example on how to start Java VisualVM and connect it to a JVM process running on the local machine.
First, Let's run Java VisualVM and connect it to a JVM process running on the local machine.
1. To set up the running JVM process, we can my simple test program called LongSleep.java:
/* LongSleep.java #- Copyright (c) 2015, HerongYang.com, All Rights Reserved. */ class LongSleep { public static void main(String[] a) { Runtime rt = Runtime.getRuntime(); System.out.println(" Free memory: " + rt.freeMemory()); System.out.println("Total memory: " + rt.totalMemory()); try {Thread.sleep(1000*60*60);} catch (InterruptedException e) {} } }
2. Compile and run it with HotSpot 1.8.0 in a command line window:
C:\herong>\progra~1\java\jdk1.8.0\bin\javac LongSleep.java C:\herong>\progra~1\java\jdk1.8.0\bin\java LongSleep Free memory: 15964984 Total memory: 16252928
3. Launch Java VisualVM in another command line window:
C:\herong>\progra~1\java\jdk1.8.0\bin\jvisualvm The launcher has determined that the parent process has a console and will reuse it for its own console output. Closing the console will result in termination of the running program. Use '--console suppress' to suppress console output. Use '--console new' to create a separate console window.
4. Double-click on "LongSleep" under "Local" in the Application panel. Java VisualVM connects to the running JVM of LongSleep.java and display the JVM summary information on the Overview tab:
PID: 560 Host: localhost Main class: LongSleep Arguments: <none> JVM: Java HotSpot(TM) Client VM (25.0-b70, mixed mode) Java: version 1.8.0, vendor Oracle Corporation Java Home: C:\progra~1\java\jdk1.8.0\jre JVM Flags: <none> Heap dump on OOME: disabled
Okay. We have successfully connected Java VisualVM to a JVM process running on the local machine.
Last update: 2015.
Table of Contents
'javac' - The Java Program Compiler
'java' - The Java Program Launcher
'jconsole' - Java Monitoring and Management Console
'jstat' - JVM Statistics Monitoring Tool
►jvisualvm (Java VisualVM) - JVM Visual Tool
What Is jvisualvm (Java VisualVM)?
jvisualvm Command to Open Dump Files or Conections
►Connecting Java VisualVM to a Local JVM Process
Monitoring Usgaes of CPU, Heap, Classes and Threads
Monitoring Thread Status as Timeline
Taking Thread Dump to See Thread Stack Traces
Taking Heap Dump to See Memory Usages
Connecting to Remote JVM Processes
Avaible Plugins and Installation
'javap' - The Java Class File Disassembler
'keytool' - Public Key Certificate Tool