how to get the min and max heap size settings of a JVM from within a Java program

后端 未结 4 490
心在旅途
心在旅途 2020-12-16 19:02

How to get the min and max heap size settings of a VM from within a Java program?

相关标签:
4条回答
  • 2020-12-16 19:43

    maybe that could help you ?

    http://download.oracle.com/docs/cd/E11035_01/wls100/perform/JVMTuning.html#wp1109778 http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp http://blog.paulgu.com/2008/07/19/6-common-errors-in-setting-java-heap-size/

    0 讨论(0)
  • 2020-12-16 19:52

    max heap size:

    Runtime.getRuntime().maxMemory();
    

    Some other calculations which you may find interesting:

    Runtime runtime = Runtime.getRuntime();
    long maxMemory = runtime.maxMemory();
    long allocatedMemory = runtime.totalMemory();
    long freeMemory = runtime.freeMemory();
    long totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
    long usedMemory = maxMemory - totalFreeMemory;
    
    0 讨论(0)
  • 2020-12-16 19:52

    You just need to use the Runtime object with Runtime.getRuntime() and then use methods like totalMemory() and freeMemory().

    0 讨论(0)
  • 2020-12-16 20:07
    ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()
    
    0 讨论(0)
提交回复
热议问题