What is vmid - and how to find it using JPS


In this tutorial we will learn what are vmid and jps and how to find vmid using JPS.

Contents of page >
  • What is vmid?
  • What is jps?
  • 1) First Write java program - (we will find vmid i.e. jvm id on which this program is running)>
  • 2) Use jps to find the vmid
    • What is jps?
    • Location of jps?
    • Go to CMD and type below commands to use JPS>


What is vmid?
vmid stands for (virtual machine id) or (JVM id).
Vmid is process id of running JVM.

What is jps?
JPS is Java Virtual Machine Process Status Tool.
The jps tool lists the HotSpot Java Virtual Machines (JVMs) running on system.

1) First Write java program - (we will find vmid i.e. jvm id on which this program is running)>
import java.util.ArrayList;
import java.util.List;
public class JstatTestingGarbageCollectionExample {
   public static void main(String[] args) {
          List<String> l = new ArrayList<String>();
          for (int i = 0; i < 100000000; i++) {
                 l = new ArrayList<String>();
                 l.add("a");
                 System.out.println(l);
          }
          System.out.println("Done");
   }
}

Execute the above java program. And this program will take long time to complete (Because of for loop).
And while program is executing follow step 2 to find vmid (i.e. before program execution completes - If we execute below steps after programs execution is over - output will be command not found).


2) Use jps to find the vmid

Location of jps?
jps is located in {javaHome\bin}

In my system jps is located in C:\Program Files\Java\jdk1.8.0_05\bin\jps.exe


Go to CMD and type below commands to use JPS>

C:\>cd C:\Program Files\Java\jdk1.8.0_05\bin

C:\Program Files\Java\jdk1.8.0_05\bin>jps
16048
1108 JstatTestingGarbageCollectionExample
23208 Jps

C:\Program Files\Java\jdk1.8.0_05\bin>



1108 is the vmid for which we were looking for.
1108 is jvm id on which this program is running




Summary -

So in this core java tutorial we learned What are vmid and jps and how to find vmid using JPS.


Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.



RELATED LINKS>

Most important and frequently used VM (JVM) PARAMETERS with examples in JVM Heap memory in java


No comments:

Post a Comment