Memory Check From Sun (Oracle) JVM on Windows

java.lang.management.OperatingSystemMXBean mxbean = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
 com.sun.management.OperatingSystemMXBean sunmxbean = (com.sun.management.OperatingSystemMXBean) mxbean;
 long freeMemory = sunmxbean.getFreePhysicalMemorySize()/1048576; 
 long availableMemory = sunmxbean.getTotalPhysicalMemorySize()/1048576; // Megs 1,024 x 1,024
 
 System.out.println("Free=" + freeMemory + " Avail=" + availableMemory);

Written By bunkertor

Leave a Reply

Your email address will not be published. Required fields are marked *