Could someone clarify the function of the xms and xmx parameters? Additionally, what are the default values assigned to these parameters when the JVM starts up?
3 comments
10 answers
-xmx and -xms are the parameters used to adjust the heap size.
-Xms:It is used for setting the initial and minimum heap size. It is recommended to set the minimum heap size equivalent to the maximum heap size in order to minimize the garbage collection.
-Xmx: It is used for setting the maximum heap size. The performance will decrease if the max heap value is set lower than the amount of live data. It will force frequent garbage collections in order to free up space.
So, you can say that the JVM will start working with with -Xms amount of memory and further it will be able to use a maximum of -Xmx amount of memory. For example,
java -Xms256m -Xmx2048m
This means, JVM will startup with 256 MB of memory and will allow the process to use up to 2048 MB of memory.
By default, there is no value set for xms, and for xmx its 256MB. You can specify it in multiple formats like kilobytes, megabytes, etc.
-Xmx1024k -Xmx512m -Xmx8g
java -X
It is important to note that the Xms flag does not have a default value, while the Xmx flag generally defaults to 256 MB. These flags are particularly useful when addressing a java.lang.OutOfMemoryError.
- -Xmx: to define the maximum heap size
- -Xms: to define the initial Java heap size