内存使用情况查看

import java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;

public class Test {
    public static void main(String[] args) {
    	OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    	System.out.println("系统物理内存总计:" + osmb.getTotalPhysicalMemorySize() / 1024 / 1024 + "MB");
    	System.out.println("系统物理可用内存总计:" + osmb.getFreePhysicalMemorySize() / 1024 / 1024 + "MB");
    }
}

 

你可能感兴趣的:(java,sun)