「jcmd」是JVM 診斷工具,它是一個命令列工具,用於在本地針對給定JVM運行診斷命令機器。工具從Java 7版本開始就包含在JDK安裝中,可以用「%java_home%\bin\jcmd.exe」程式檔案表示。如果我們在環境變數「path」中包含「%java_home%\bin」目錄,我們可以執行「jcmd -h」命令來查看所有目錄的完整清單選項如下
<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>
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) { } } }
<strong>Free memory: 65454560 Total memory: 67108864</strong>
#我們可以使用「jcmd -l」命令列出本地上所有正在運行的JVM機器,然後使用輸出中的PID 或類別main 來識別JVM。
<strong>C:\Users\User>jcmd -l</strong> <strong>6108 jdk.jcmd/sun.tools.jcmd.JCmd -l</strong>
以上是jcmd工具在Java 9中的重要性是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!