Finding out system RAM via Java

蹲街弑〆低调 提交于 2019-12-31 03:25:31

问题


I am writing a program in which i need to do a minimum system RAM validation. How do i go about calculating the RAM of the machine that is executing the code in its JVM ?


回答1:


I think it is not possible with pure java at all.

Within the JVM you can only mesure the JVM-ram not the System RAM. http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/management/MemoryMXBean.html

You'll need a piece of native code.




回答2:


You can have a look into Runtime class:

Runtime.getRuntime().maxMemory();

but from Runtime docs:

Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned



来源:https://stackoverflow.com/questions/9327055/finding-out-system-ram-via-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!