@Exported public interface SystemResourcePressureMXBean extends PlatformManagedObject
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.
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
.
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
.ManagementFactory.getPlatformMXBean(java.lang.Class<T>)
,
MBeanServer
Modifier and Type | Method and Description |
---|---|
int |
getMemoryPressure()
Gets the current memory pressure level.
|
void |
setMemoryPressure(int pressureLevel)
Sets the current memory pressure level.
|
getObjectName
int getMemoryPressure()
void setMemoryPressure(int pressureLevel)
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.pressureLevel
- A level from 0-10 inclusiveIllegalArgumentException
- 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").
Copyright © 2014, 2015, Oracle and/or its affiliates. All rights reserved.