I was expecting Runtime.maxMemory() to return exactly the -Xmx but it returns a lower value. So what does it return?
getRuntime() method returns the runtime object associated with the current Java application. Most of the methods of class Runtime are instance methods and must be invoked with respect to the current runtime object.
Runtime class is a subclass of Object class, can provide access to various information about the environment in which a program is running. The Java run-time environment creates a single instance of this class that is associated with a program.
getRuntime() Returns the instance or Runtime object associated with the current Java application. halt(int status) Forcibly terminates the currently running Java virtual machine. This method never returns normally.
The interpretation of the -Xmx flag is VM-dependent. Some VMs, including HotSpot, enforce a lower bound on the effective value of this option. The CCC proposal should not have mentioned the -Xmx flag in this way.
Reference
Returns the maximum amount of memory that the Java virtual machine will attempt to use, jvm may not use all the memory you have defined as -Xmx
parameter for just heap.
-Xmxn
Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts. Examples:
-Xmx83886080 -Xmx81920k -Xmx80m
maxMemory()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With