Interface SystemResourcePressureMXBean

  • All Superinterfaces:
    PlatformManagedObject


    public interface SystemResourcePressureMXBean
    extends PlatformManagedObject
    When using Cooperative Memory Management, the SystemResourcePressureMXBean serves to communicate memory pressure to the VM. Memory pressure represents the total memory usage (RAM) on the system. The higher the pressure, the closer you are to running out of memory.

    A Java virtual machine can have at most one instance of a SystemResourcePressureMXBean. The ObjectName for uniquely identifying the SystemResourcePressureMXBean within an MBeanServer is: "com.oracle.management:type=ResourcePressureMBean". It can be obtained by calling the PlatformManagedObject.getObjectName() method.

    Notifications

    A SystemResourcePressureMXBean implementation must be a NotificationEmitter, to allow one or more notification listeners to be registered for receiving a notification when the memory pressure changes.

    This MXBean will emit an AttributeChangeNotification when the memory pressure is changed. Applications can react to memory pressure by adding their own NotificationListener.

    Registration

    Code similar to the following should be used to register this MXBean:

    
         SystemResourcePressureMXBean mxbean =
           ManagementFactory.getPlatformMXBean(SystemResourcePressureMXBean.class);
         ManagementFactory.getPlatformMBeanServer().registerMBean(mxbean, mxbean.getObjectName());
     
    Note that because Cooperative Memory Management is a commercial feature, in order to use it the VM must be running with -XX:+UnlockCommercialFeatures. Otherwise, ManagementFactory.getPlatformMXBean(java.lang.Class<T>) will throw an IllegalArgumentException.
    Since:
    8u40
    See Also:
    ManagementFactory.getPlatformMXBean(java.lang.Class<T>), MBeanServer
    • Method Detail

      • getMemoryPressure

        int getMemoryPressure​()
        Gets the current memory pressure level.
        Returns:
        The current memory pressure level
      • setMemoryPressure

        void setMemoryPressure​(int pressureLevel)
        Sets the current memory pressure level. The MemoryPressure attribute can take values from 0 through 10, where 0 indicates very little memory pressure and 10 means the system is very low on memory. If the current memory pressure level is already at pressureLevel, no action is taken and no notifications are sent.
        Parameters:
        pressureLevel - A level from 0-10 inclusive
        Throws:
        IllegalArgumentException - if the pressureLevel provided is outside the range of 0-10 inclusive.
        SecurityException - if a security manager exists and the caller does not have ManagementPermission("control").