This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.
After touching the JVM, besides the memory structure/model, I heard more about the JVM parameters. How to configure the JVM parameters is usually considered in the Java program tuning, and it is one of the most frequently asked knowledge points in the interview, which is of great importance.
One, foreword
1.Java VIRTUAL Machine memory model, as the beginning of the JVM series, describes the MEMORY structure of the JVM, the status and role of each part in the Java program, from which we initially understand that the size of each part of the parameter allocation on the Java program is a certain impact (performance). This article describes how to set JVM parameters, such as heap size, generation size, persistence band size, thread stack size, etc.
JVM parameter list:
Parameter names | Parameter meaning |
---|---|
-Xmx | Maximum heap memory |
-Xms | Minimum heap memory |
-Xmn | Cenozoic size |
-XX:MaxPermSize | Maximum number of persistent generations |
-XX:PermSize | The initial size of the persistent generation |
-Xss | Size of thread stack |
Second, JVM parameter setting method
For those of you who are not sure how to set the parameters, this section provides a brief explanation. If you are sure, you can skip this section. (Specific JVM parameters are set according to actual conditions. The following parameter Settings are only examples.)
1. Set JVM parameters on Eclipse
Window->Preferences->Java->Installed JARs edit the current JRE and enter the JVM parameters to be configured in the “Default VM Arguments” box, as shown in the following figure:
2. Set JVM parameters on IDEA
Run-> Edit Configurations, as shown below:
3. Set JVM parameters on Tomcat
In /tomcat/bin/catalina.bat, set JAVA_OPTS=%JAVA_OPTS%…. After this sentence add:
set JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx1024m
Copy the code
Restart Tomcat for the Settings to take effect.
4. Set JVM parameters in the script
Set in the Java program execution script as follows:
java -Xms1024M -Xmx1024M com.xcbeyond.study.jvm.XmxTest
Copy the code
Set maximum heap memory
The maximum heap that can be used by a Java program can be set with the -xmx parameter. The maximum heap is the maximum size of the new generation and the old generation combined. It is the upper limit of the Java program heap.