“jcmd”是 jvm 诊断工具,它是一个命令行工具,用于在本地针对给定 jvm 运行诊断命令机器。该工具从java 7版本开始就包含在jdk安装中,可以用“%java_home%\bin\jcmd.exe”程序文件表示。如果我们在环境变量“path”中包含“%java_home%\bin”目录,我们可以运行“jcmd -h”命令来查看所有目录的完整列表选项如下
c:\users\user>jcmd -husage: 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
示例public class jcmdtooltest { public static void main(string args[]) { runtime runtime = runtime.getruntime(); system.out.println("free memory: " + runtime.freememory()); system.out.println("total memory: " + runtime.totalmemory()); try { thread.sleep(5000); } catch(interruptedexception e) { } }}
输出free memory: 65454560total memory: 67108864
我们可以使用“jcmd -l”命令列出本地上所有正在运行的 jvm机器,然后使用输出中的 pid 或类 main 来识别 jvm。
c:\users\user>jcmd -l6108 jdk.jcmd/sun.tools.jcmd.jcmd -l
以上就是jcmd工具在java 9中的重要性是什么?的详细内容。