Getting OS memory size from java

前端 未结 3 767
醉梦人生
醉梦人生 2020-12-20 14:02

Are there any way to get the size of the total memory on the operating system from java? Using

Runtime.getRuntime().maxMemory()

returns the

3条回答
  •  無奈伤痛
    2020-12-20 14:35

    com.sun.management.OperatingSystemMXBean bean =
      (com.sun.management.OperatingSystemMXBean)
        java.lang.management.ManagementFactory.getOperatingSystemMXBean();
    long max = bean.getTotalPhysicalMemorySize();
    

    returns available RAM size for JVM (limited by 32bit), not the heap size.

提交回复
热议问题