java.lang.Object
com.sun.management.GarbageCollectionNotificationInfo
- 所有已实现的接口:
-
CompositeDataView
关于垃圾回收的信息
当Java虚拟机完成垃圾回收操作时,GarbageCollectorMXBean会发出垃圾回收通知。发出的通知将包含有关内存状态的垃圾回收通知信息:
- 用于执行回收的垃圾收集器的名称。
- 垃圾收集器执行的操作。
- 垃圾回收操作的原因。
- 包含有关GC周期的一些统计信息的
GcInfo对象(开始时间,结束时间)以及GC周期前后的内存使用情况。
表示GarbageCollectionNotificationInfo对象的CompositeData存储在notification的userdata中。提供了一个from方法,用于将CompositeData转换为GarbageCollectionNotificationInfo对象。例如:
Notification notif;
// 接收由GarbageCollectorMXBean发出的通知并设置为notif
...
String notifType = notif.getType();
if (notifType.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
// 检索垃圾回收通知信息
CompositeData cd = (CompositeData) notif.getUserData();
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(cd);
....
}
GarbageCollectorMXBean发出的通知类型是:
- 垃圾回收通知。
每个垃圾收集器发出的通知都使用,关于通知的详细信息在action字符串中提供
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGarbageCollectionNotificationInfo(String gcName, String gcAction, String gcCause, GcInfo gcInfo) 构造一个GarbageCollectionNotificationInfo对象。 -
Method Summary
Modifier and TypeMethodDescriptionfrom(CompositeData cd) 返回由给定CompositeData表示的GarbageCollectionNotificationInfo对象。返回垃圾收集器执行的操作返回垃圾回收的原因返回与上次垃圾回收相关的GC信息返回用于执行回收的垃圾收集器的名称返回与此对象中的值对应的CompositeData。
-
Field Details
-
GARBAGE_COLLECTION_NOTIFICATION
表示Java虚拟机已完成垃圾回收周期的通知类型。此通知由GarbageCollectorMXBean发出。此通知类型的值为com.sun.management.gc.notification。- 参见:
-
-
Constructor Details
-
Method Details
-
getGcName
返回用于执行回收的垃圾收集器的名称- 返回:
- 用于执行回收的垃圾收集器的名称
-
getGcAction
返回垃圾收集器执行的操作- 返回:
- 垃圾收集器执行的操作
-
getGcCause
返回垃圾回收的原因- 返回:
- 垃圾回收的原因
-
getGcInfo
返回与上次垃圾回收相关的GC信息- 返回:
- 与上次垃圾回收相关的GC信息
-
from
返回由给定CompositeData表示的GarbageCollectionNotificationInfo对象。给定的CompositeData必须包含以下属性:属性名称 类型 gcName java.lang.StringgcAction java.lang.StringgcCause java.lang.StringgcInfo javax.management.openmbean.CompositeData- 参数:
-
cd- 表示GarbageCollectionNotificationInfo的CompositeData - 返回:
-
如果
cd不为null,则返回由cd表示的GarbageCollectionNotificationInfo对象;否则返回null。 - 抛出:
-
IllegalArgumentException- 如果cd不表示GarbaageCollectionNotificationInfo对象。
-
toCompositeData
从接口复制的描述:CompositeDataView返回与此对象中的值对应的
CompositeData。返回的值通常应该是CompositeDataSupport的实例,或者通过writeReplace方法序列化为CompositeDataSupport的类。否则,接收该对象的远程客户端可能无法重建它。- 指定者:
-
toCompositeData在接口CompositeDataView中 - 参数:
-
ct- 期望的返回值的CompositeType。如果返回值为cd,则应该为cd.getCompositeType().equals(ct)为true。通常这是因为cd是使用ct作为其CompositeType构造的CompositeDataSupport。 - 返回:
-
CompositeData。
-