I'm trying to set the maximum amount of bytes that the JVM process will try to allocate. Im not talking about the heap but total amount of memory on OS level. I've looked hard but haven't found any solutions, which I find hard to believe. Even with Java 10 which should be able to stay within container memory boundaries.
This question has been asked before some 9 years ago (See: How to set the maximum memory usage for JVM?) but the answer is incorrect.
The Runtime
object contains a maxMemory()
method which is incorrectly documented as follows:
Returns the maximum amount of memory that the Java virtual machine will attempt to use.
The maxMemory()
method returns the maximum amount of Heap and not the total amount of memory the JVM process can claim.
Question: Is it really true that the JVM cannot manage a hard limit on its own memory use?