Home > Java > javaTutorial > What is the importance of jcmd tool in Java 9?

What is the importance of jcmd tool in Java 9?

PHPz
Release: 2023-09-15 18:21:03
forward
1377 people have browsed it

jcmd工具在Java 9中的重要性是什么?

"jcmd" is the JVM Diagnostic tool, which is a command line tool used to target a given JVM locally Run diagnostic commands on the machine. This tool is included in the JDK installation starting from version Java 7 and can be represented by the "%java_home%\bin\jcmd.exe" program file. If we include the "%java_home%\bin" directory in the environment variable "path", we can run the "jcmd -h" command to see the complete list of all directories. Options are as follows

<strong>C:\Users\User>jcmd -h
Usage: jcmd
   or: jcmd -l
   or: jcmd -h

   command must be a valid jcmd command for the selected jvm.
   Use the command "help" to see which commands are available.
   If the pid is 0, commands will be sent to all Java processes.
   The main class argument will be used to match (either partially
   or fully) the class used to start Java.
   If no options are given, lists Java processes (same as -l).

   PerfCounter.print display the counters exposed by this process
   -f read and execute commands from the file
   -l list JVM processes on the local machine
   -h this help</strong>
Copy after login

Example

public class JCmdToolTest {
   public static void main(String args[]) {
      <strong>Runtime </strong>runtime = Runtime.<strong>getRuntime()</strong>;
      System.out.println("Free memory: " + runtime.<strong>freeMemory()</strong>);
      System.out.println("Total memory: " + runtime.<strong>totalMemory()</strong>);
      try {
         Thread.sleep(5000);
      } catch(InterruptedException e) {
      }
   }
}
Copy after login

Output

<strong>Free memory: 65454560
Total memory: 67108864</strong>
Copy after login

##We can use the "

jcmd -l" command line Output all running JVM machines locally and use the PID or class main in the output to identify the JVM.

<strong>C:\Users\User>jcmd -l</strong>
<strong>6108 jdk.jcmd/sun.tools.jcmd.JCmd -l</strong>
Copy after login

The above is the detailed content of What is the importance of jcmd tool in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template