jcmd 工具在 Java 9 中的意義是什麼?
“jcmd”是 JVM 診斷工具,它是一個命令列工具,用於對本地計算機上給定的 JVM 執行診斷命令。從Java 7版本開始,此工具已包含在 JDK 安裝中,並且可以使用“%java_home%\bin\jcmd.exe”程式檔案來表示。如果我們在“path”環境變數中包含“%java_home%\bin”目錄,則可以執行“jcmd -h”命令以檢視以下所有選項的完整列表
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
示例
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: 65454560 Total memory: 67108864
我們可以使用“jcmd -l”命令列出本地計算機上執行的所有 JVM,然後使用輸出中的PID或類main來識別 JVM。
C:\Users\User>jcmd -l 6108 jdk.jcmd/sun.tools.jcmd.JCmd -l
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP