- java.lang.Object
-
- java.lang.management.MemoryUsage
-
public class MemoryUsage extends Object
MemoryUsage对象表示内存使用的快照。MemoryUsage类的实例通常由用于获取关于Java虚拟机的单个内存池或整个Java虚拟机的堆或非堆内存的内存使用信息的方法构建。A
Describes the MemoryUsage object contentMemoryUsage对象包含四个值:initrepresents the initial amount of memory (in bytes) that the Java virtual machine requests from the operating system for memory management during startup. The Java virtual machine may request additional memory from the operating system and may also release memory to the system over time. The value ofinitmay be undefined.usedrepresents the amount of memory currently used (in bytes).committedrepresents the amount of memory (in bytes) that is guaranteed to be available for use by the Java virtual machine. The amount of committed memory may change over time (increase or decrease). The Java virtual machine may release memory to the system andcommittedcould be less thaninit.committedwill always be greater than or equal toused.maxrepresents the maximum amount of memory (in bytes) that can be used for memory management. Its value may be undefined. The maximum amount of memory may change over time if defined. The amount of used and committed memory will always be less than or equal tomaxifmaxis defined. A memory allocation may fail if it attempts to increase the used memory such thatused > committedeven ifused <= maxwould still be true (for example, when the system is low on virtual memory).
以下是显示内存池示例的图片:+----------------------------------------------+ +//////////////// | + +//////////////// | + +----------------------------------------------+ |--------| init |---------------| used |---------------------------| committed |----------------------------------------------| maxMXBean映射
MemoryUsage被映射到CompositeData作为指定具有属性from方法。- 从以下版本开始:
- 1.5
-
-
构造方法摘要
构造方法 Constructor 描述 MemoryUsage(long init, long used, long committed, long max)构造一个MemoryUsage对象。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 static MemoryUsagefrom(CompositeData cd)返回由给定的CompositeData表示的MemoryUsage对象。longgetCommitted()返回为Java虚拟机提供的内存量(以字节计)。longgetInit()返回Java虚拟机最初从操作系统请求进行内存管理的以字节为单位的内存量。longgetMax()返回可用于内存管理的最大内存量(以字节为单位)。longgetUsed()以字节为单位返回使用的内存量。StringtoString()返回此内存使用情况的描述性表示。
-
-
-
构造方法详细信息
-
MemoryUsage
public MemoryUsage(long init, long used, long committed, long max)构造一个MemoryUsage对象。- 参数
-
init- Java虚拟机分配的初始内存量(以字节为单位) 或-1如果未定义。 -
used- 以字节为单位的已用内存量。 -
committed- 提交的内存量(以字节为单位)。 -
max- 可以使用的最大内存量(以字节为单位) 或-1如果未定义。 - 异常
-
IllegalArgumentException- 如果-
init或max值为负数,而不是-1; 要么 -
used或committed值为负数; 要么 -
used大于值committed; 要么 -
committed如果被定义,大于maxmax的值。
-
-
-
方法详细信息
-
getInit
public long getInit()
返回Java虚拟机最初从操作系统请求进行内存管理的以字节为单位的内存量。 如果初始内存大小未定义,则此方法返回-1。- 结果
-
内存的初始大小(以字节为单位)
-1如果未定义。
-
getUsed
public long getUsed()
以字节为单位返回使用的内存量。- 结果
- 使用的内存量(以字节为单位)。
-
getCommitted
public long getCommitted()
返回为Java虚拟机提供的内存量(以字节计)。 Java虚拟机可以使用这种内存量。- 结果
- 提交的内存量以字节为单位。
-
getMax
public long getMax()
返回可用于内存管理的最大内存量(以字节为单位)。 如果最大内存大小未定义,则此方法返回-1。如果内存量大于已提交内存量,则不能保证此内存量可用于内存管理。 即使所使用的内存量不超过此最大大小,Java虚拟机也可能无法分配内存。
- 结果
-
最大内存量(以字节为单位)
-1如果未定义。
-
from
public static MemoryUsage from(CompositeData cd)
返回由给定的CompositeData表示的MemoryUsage对象。 给定的CompositeData必须包含以下属性:Attribute Name Type init java.lang.Longused java.lang.Longcommitted java.lang.Longmax java.lang.Long- 参数
-
cd-CompositeData代表MemoryUsage - 结果
-
一个
MemoryUsage通过表示对象cd如果cd不是null; 否则为null。 - 异常
-
IllegalArgumentException- 如果cd不代表具有上述属性的MemoryUsage。
-
-