How do I find the physical memory size in Java?

前端 未结 7 878
心在旅途
心在旅途 2021-01-07 22:02

I\'m writing an installer that will tune the configuration of the product for the particular hardware on which it will be run. In particular, I want to determine how much p

7条回答
  •  既然无缘
    2021-01-07 22:48

    You can use the following Java code to query the physical memory:

    com.sun.management.OperatingSystemMXBean os = (com.sun.management.OperatingSystemMXBean)
         java.lang.management.ManagementFactory.getOperatingSystemMXBean();
    long physicalMemorySize = os.getTotalPhysicalMemorySize();
    

    But the package com.sun.management is optional and need not be available on every platform.

提交回复
热议问题