I’m writing a Java application that needs to check the maximum amount of RAM available in the system (not the one available for the VM). Is there a portable way to do so?
Thanks a lot 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
JMX you can access the FreePhysicalMemorySize and TotalPhysicalMemorySize attributes of java.lang:type=OperatingSystem. These attributes are not really documented in the JavaDocs so they are probably not guaranteed on all JVMs and platforms, but they were available to me (using Sun’s JVM).
In your Java code you can get access to the MBean via: ManagementFactory.getOperatingSystemMXBean()
These properties are documented in the JavaDoc for Sun’s implementation so I think you may rely on them if your application runs on their JVM.