Finding out system RAM via Java

后端 未结 2 1262
野的像风
野的像风 2021-01-22 22:13

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 ?

2条回答
  •  后悔当初
    2021-01-22 22:40

    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

提交回复
热议问题