java.lang.Object
java.lang.management.MemoryNotificationInfo
关于内存通知的信息。
当Java虚拟机检测到内存池的内存使用量超过阈值时,MemoryMXBean会发出内存通知。发出的通知将包含有关检测到的条件的内存通知信息:
存储在用户数据中的代表MemoryNotificationInfo对象的CompositeData。提供了一个from方法,用于将CompositeData转换为MemoryNotificationInfo对象。例如:
Notification notif;
// 接收MemoryMXBean发出的通知并设置为notif
...
String notifType = notif.getType();
if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) ||
notifType.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
// 检索内存通知信息
CompositeData cd = (CompositeData) notif.getUserData();
MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
....
}
MemoryMXBean发出的通知类型有:
使用阈值超出通知。
当内存池的内存使用量增加并达到或超过其使用阈值值时,将发出此通知。后续再次越过使用阈值不会再触发通知,直到内存使用量降低到低于使用阈值。收集使用阈值超出通知。
当内存池的内存使用量大于或等于其收集使用阈值后,Java虚拟机在回收该内存池中未使用对象时会发出此通知。
- 自Java版本:
- 1.5
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMemoryNotificationInfo(String poolName, MemoryUsage usage, long count) 构造一个MemoryNotificationInfo对象。 -
Method Summary
Modifier and TypeMethodDescriptionstatic MemoryNotificationInfofrom(CompositeData cd) 返回由给定CompositeData表示的MemoryNotificationInfo对象。longgetCount()返回在构造通知时内存使用量越过阈值的次数。返回触发此通知的内存池的名称。getUsage()返回构造通知时内存池的内存使用量。
-
Field Details
-
MEMORY_THRESHOLD_EXCEEDED
表示内存池的内存使用量已达到或超过其使用阈值值的通知类型。此通知由MemoryMXBean发出。后续再次越过使用阈值不会再触发通知,直到内存使用量降低到低于使用阈值。此通知类型的值为java.management.memory.threshold.exceeded。- 参见:
-
MEMORY_COLLECTION_THRESHOLD_EXCEEDED
表示内存池的内存使用量大于或等于其收集使用阈值后,Java虚拟机在回收该内存池中未使用对象时发出的通知类型。此通知由MemoryMXBean发出。此通知类型的值为java.management.memory.collection.threshold.exceeded。- 参见:
-
-
Constructor Details
-
MemoryNotificationInfo
构造一个MemoryNotificationInfo对象。- 参数:
-
poolName- 触发此通知的内存池的名称。 -
usage- 内存池的内存使用量。 -
count- 阈值越过计数。
-
-
Method Details
-
getPoolName
返回触发此通知的内存池的名称。内存池使用已越过阈值。- 返回:
- 触发此通知的内存池的名称。
-
getUsage
返回构造通知时内存池的内存使用量。- 返回:
- 构造通知时内存池的内存使用量。
-
getCount
public long getCount()- 返回:
- 在构造通知时内存使用量越过阈值的次数。
-
from
返回由给定CompositeData表示的MemoryNotificationInfo对象。给定的CompositeData必须包含以下属性:属性名称 类型 poolName java.lang.Stringusage javax.management.openmbean.CompositeDatacount java.lang.Long- 参数:
-
cd- 表示MemoryNotificationInfo的CompositeData - 返回:
-
如果
cd不为null,则返回由cd表示的MemoryNotificationInfo对象;否则返回null。 - 抛出:
-
IllegalArgumentException- 如果cd不表示MemoryNotificationInfo对象。
-