This article is participating in the Java Theme Month – Java Debug Notes Event, see the event link for details

What are the -xms and -xmx parameters when starting the JVM?

Explain the use of Xms and Xmx parameters in the JVM. What are their default values?

Answer:


A lot of knowledge points, really need to write out will master ! ! !   \color{purple} a lot of knowledge points, really need to write out just can master!! {~}

The flag Xmx specifies the maximum memory allocation pool for the Java Virtual machine (JVM), while Xms specifies the initial memory allocation pool.

This means that your JVM will start with Xms memory and will be able to use the maximum amount of Xmx memory. For example, starting the JVM shown below will start it with 256 MB of memory, and will allow the process to use up to 2048 MB of memory:

java -Xms256m -Xmx2048m

Memory flags can also be specified in different sizes (e.g., kilobytes, megabytes, etc.).

-Xmx1024k
-Xmx512m
-Xmx8g
Copy the code

This Xms flag has no default value, Xmx usually has a default value of 256 MB. These signs of common usage is when you meet a Java lang. OutOfMemoryError.

When using these Settings, keep in mind that these Settings apply to the JVM’s heap, and that the JVM can and will use more memory than just the size allocated to the heap. From the Oracle documentation:

Note that the JVM uses more memory than just the heap. For example, Java methods, thread stacks, and native handles are allocated in memory separately from the heap and JVM internal data structures.

The article translated from yl2gl72eozkinivz3vc6swkesy – ac4c6men2g7xr2a – translate. Translate. Goog/questions / 1…

The authors suggest: using equal maximum and minimum memory, the garbage collector says a lot

Garbage collection algorithm, CMS, G1, ZGC, etc., garbage collection standards, how to avoid memory leakage and memory overflow, troubleshooting methods jStack, Jstat, JMAP, etc. Use Alsatian diagnostic tools, etc.

Here gives a better explanation: zhuanlan.zhihu.com/p/143077966


Welcome to my column S t a c k O v e r F l o w . I select the best questions and answers and test them frequently in interviews ! ! !   \color{red} Welcome to my column StackOverFlow, I will filter the quality of the interview test!! {~}


There are the latest and elegant ways to do this, and I will write my thoughts on this q&A at the end of the article \color{red} has the latest, elegant implementation, and I will also write my opinion on this question at the end of the article {~}

Thank you for reading this, if this article is well written and if you feel there is something to it

Ask for a thumbs up 👍 ask for attention ❤️ ask for share 👥 for 8 abs I really very useful!!

If there are any mistakes in this blog, please comment, thank you very much! ❤ ️ ❤ ️ ❤ ️ ❤ ️