参考:http://cn-done.iteye.com/blog/2041971

package com.wjz.demo;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.util.List;

public class JVMArgs {

    public static void main(String[] args) {
        MemoryMXBean memorymbean = ManagementFactory.getMemoryMXBean();
        System.out.println("堆内存信息: " + memorymbean.getHeapMemoryUsage());   
        System.out.println("方法区内存信息: " + memorymbean.getNonHeapMemoryUsage()); 
        
        List<String> inputArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
        System.out.println("\n#####################运行时设置的JVM参数#######################");
        System.out.println(inputArgs);
        
        System.out.println("\n#####################运行时内存情况#######################");
        long totle = Runtime.getRuntime().totalMemory();
        System.out.println("总的内存量 [" + totle + "]");
        long free = Runtime.getRuntime().freeMemory();
        System.out.println("空闲的内存量 [" + free + "]");
        long max = Runtime.getRuntime().maxMemory();
        System.out.println("最大的内存量 [" + max + "]");
    }
}

输出结果

堆内存信息: init = 20971520(20480K) used = 857216(837K) committed = 20119552(19648K) max = 20119552(19648K)
方法区内存信息: init = 24313856(23744K) used = 3082720(3010K) committed = 24313856(23744K) max = 136314880(133120K)

#####################运行时设置的JVM参数#######################
[-Xmx20M, -Dfile.encoding=UTF-8]

#####################运行时内存情况#######################
总的内存量 [20119552]
空闲的内存量 [19262336]
最大的内存量 [20119552]

 

相关文章:

  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
  • 2021-12-04
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2021-10-23
  • 2021-09-30
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案