如何通过jstat命令进行查看堆内存使用情况?

时间:2023-02-08 11:14:50
摘要:jstat命令可以查看堆内存各部分的使用量,以及加载类的数量。

本文分享自华为云社区《JVM之通过jstat命令进行查看堆内存使用情况》,作者:共饮一杯无 。

基本概念

jstat是JDK自带的一个轻量级小工具。它位于java的bin目录下,主要利用JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括了对Heap size和垃圾回收状况的监控。jstat命令可以查看堆内存各部分的使用量,以及加载类的数量。命令的格式如下:

jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数]

C:\Users\zjq>jstat -help
Usage: jstat -help|-options
 jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Definitions:
 <option>      An option reported by the -options option
 <vmid>        Virtual Machine Identifier. A vmid takes the following form:
 <lvmid>[@<hostname>[:<port>]]
                Where <lvmid> is the local vm identifier for the target
                Java virtual machine, typically a process id; <hostname> is
                the name of the host running the target Java virtual machine;
                and <port> is the port number for the rmiregistry on the
                target host. See the jvmstat documentation for a more complete
                description of the Virtual Machine Identifier.
 <lines>       Number of samples between header lines.
 <interval>    Sampling interval. The following forms are allowed:
 <n>["ms"|"s"]
                Where <n> is an integer and the suffix specifies the units as
                milliseconds("ms") or seconds("s"). The default units are "ms".
 <count>       Number of samples to take before terminating.
  -J<flag>      Pass <flag> directly to the runtime system.