package com.demo.memoryheap;
import java.lang.management.ManagementFactory;
/**
* @author abdul
*
*/
public class FreeMemoryUsingMxBean {
/**
* @param args
*/
public static void main(String[] args) {
com.sun.management.OperatingSystemMXBean mxbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
System.out.println("Total Memory in MB: " + mxbean.getTotalPhysicalMemorySize()/(1024*1024));
System.out.println("Free Memory in MB: " + mxbean.getFreePhysicalMemorySize()/(1024*1024));
}
}
Note : If you get access restriction error while working on Eclipse , check this :
Access Restriction issue
import java.lang.management.ManagementFactory;
/**
* @author abdul
*
*/
public class FreeMemoryUsingMxBean {
/**
* @param args
*/
public static void main(String[] args) {
com.sun.management.OperatingSystemMXBean mxbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
System.out.println("Total Memory in MB: " + mxbean.getTotalPhysicalMemorySize()/(1024*1024));
System.out.println("Free Memory in MB: " + mxbean.getFreePhysicalMemorySize()/(1024*1024));
}
}
Note : If you get access restriction error while working on Eclipse , check this :
Access Restriction issue
My Arcus offer java training with 100% placement. Our java training course that includes fundamentals and advance java training program with high priority jobs. java j2ee training with placement having more exposure in most of the industry nowadays in depth manner of java
ReplyDeletejava training in chennai