1.监控内存使用率
/**
* des get mem usage
* @return
*/
private double getMemUsage()
{
double memUsage = 0;
try
{
logger.info("===============test============================");
ObjectName memObjectName = new ObjectName("java.lang:type=Memory");
MemoryUsage heapMemoryUsage = MemoryUsage.from((CompositeDataSupport) mbsc.getAttribute(memObjectName, "HeapMemoryUsage"));
long maxMemory = heapMemoryUsage.getMax();// 堆最大
long commitMemory = heapMemoryUsage.getCommitted();// 堆当前分配
long usedMemory = heapMemoryUsage.getUsed();
memUsage = (double) usedMemory / commitMemory;
logger.info("=================memUsage: " + memUsage);
}
catch(Exception e)
{
e.printStackTrace();
}
return memUsage;
}