Class GarbageCollectionNotificationInfo

java.lang.Object
com.sun.management.GarbageCollectionNotificationInfo
All Implemented Interfaces:
CompositeDataView

public class GarbageCollectionNotificationInfo extends Object implements CompositeDataView
Information about a garbage collection.

A garbage collection notification is emitted by GarbageCollectorMXBean when the Java virtual machine completes a garbage collection action. The notification emitted will contain the garbage collection notification information about the status of the memory:

  • The name of the garbage collector used perform the collection.
  • The action performed by the garbage collector.
  • The cause of the garbage collection action.
  • A GcInfo object containing some statistics about the GC cycle (start time, end time) and the memory usage before and after the GC cycle.

A CompositeData representing the GarbageCollectionNotificationInfo object is stored in the userdata of a notification. The from method is provided to convert from a CompositeData to a GarbageCollectionNotificationInfo object. For example:

      Notification notif;

      // receive the notification emitted by a GarbageCollectorMXBean and save in notif
      ...

      String notifType = notif.getType();
      if (notifType.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
          // retrieve the garbage collection notification information
          CompositeData cd = (CompositeData) notif.getUserData();
          GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(cd);
          ...
      }
 

The type of the notification emitted by a GarbageCollectorMXBean is:

  • Field Details

    • GARBAGE_COLLECTION_NOTIFICATION

      public static final String GARBAGE_COLLECTION_NOTIFICATION
      Notification type denoting that the Java virtual machine has completed a garbage collection cycle. This notification is emitted by a GarbageCollectorMXBean. The value of this notification type is "com.ibm.lang.management.gc.notification" which matches RI naming for compatibility.
      See Also:
  • Constructor Details

    • GarbageCollectionNotificationInfo

      public GarbageCollectionNotificationInfo(String gcName, String gcAction, String gcCause, GcInfo gcInfo)
      Creates a new GarbageCollectionNotificationInfo instance.
      Parameters:
      gcName - the name of the garbage collector used to perform the collection
      gcAction - the action of the performed by the garbage collector
      gcCause - the cause the garbage collection
      gcInfo - a GcInfo object providing statistics about the GC cycle
  • Method Details

    • getGcName

      public String getGcName()
      Returns:
      the name of the garbage collector used to perform the collection.
    • getGcAction

      public String getGcAction()
      Returns:
      the action of the performed by the garbage collector
    • getGcCause

      public String getGcCause()
      Returns:
      the cause of the garbage collection
    • getGcInfo

      public GcInfo getGcInfo()
      Returns:
      the GC information related to the last garbage collection
    • from

      Returns a GarbageCollectionNotificationInfo object represented by the given CompositeData. The given CompositeData must contain the following attributes:
      CompositeData attributes
      Attribute Name Type
      gcName java.lang.String
      gcAction java.lang.String
      gcCause java.lang.String
      gcInfo com.ibm.lang.management.GcInfo
      Parameters:
      cd - CompositeData representing a GarbageCollectionNotificationInfo
      Returns:
      a GarbageCollectionNotificationInfo object represented by cd if cd is not null; null otherwise
      Throws:
      IllegalArgumentException - if cd does not represent a GarbageCollectionNotificationInfo object
    • toCompositeData

      public CompositeData toCompositeData(CompositeType ct)

      Return the CompositeData representation of this GarbageCollectionNotificationInfo.

      Specified by:
      toCompositeData in interface CompositeDataView
      Parameters:
      ct - the CompositeType that the caller expects. This parameter is ignored and can be null.
      Returns:
      the CompositeData representation.