Friday, 10 August 2018

jcmd: VM.uptime: Print VM up time

jcmd provides VM.uptime command to print VM uptime.

For example,

HelloWorld.java
public class HelloWorld {
 public static void main(String args[]) throws Exception {
  Thread t1 = new Thread() {
   public void run() {
    while (true) {
     try {
      Thread.sleep(1000);
     } catch (Exception e) {

     }
    }
   }
  };

  t1.start();
 }
}


Compile and run HelloWord.java application.



Open another command prompt and execute ‘jcmd’ command.
C:\>jcmd
9504 sun.tools.jcmd.JCmd
13220
1892 HelloWorld


As you see the output of jcmd command, HelloWorld application is running with process id 1892.

Execute the command 'jcmd 1892 help' to get the list of commands available with process id 1892.

As you see below image 'VM.uptime' is available for the process id 1892.


Execute the command ‘jcmd 1892 VM.uptime -date’ to print the VM uptime.
C:\>jcmd 1892 VM.uptime -date
1892:
2018-07-27T08:26:13.055+0530: 249.897 s





Previous                                                 Next                                                 Home

No comments:

Post a Comment