Memory Information
Call the ManagementFactory.getOperatingSystemMXBean() method to obtain memory information.
Example:
import Java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
private static OperatingSystemMXBean systemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
public static int memoryLoad() {
// Obtains the total capacity of the physical memory and virtual memory.
System.out.println ("TotalSwapSpaceSize: "+systemMXBean.getTotalSwapSpaceSize() /1024+"K");
// Obtains the total capacity of the physical memory.
System.out.println ("TotalPhysicalMemorySize: " +systemMXBean.getTotalPhysicalMemorySize() /1024+"K");
// Obtains the remaining physical memory.
System.out.println ("FreePhysicalMemorySize: " +systemMXBean.getFreePhysicalMemorySize() /1024+"K");
// Obtains the remaining swap capacity.
System.out.println("FreeSwapSpaceSize:" +systemMXBean.getFreeSwapSpaceSize()/1024+"K");
}
Parent topic: Java