Home > Back-end >  In JAVA JVM parameter Settings and check the size of the heap memory
In JAVA JVM parameter Settings and check the size of the heap memory

Time:11-29

1. Set up in eclipse JVM parameter

2. Set the JVM parameters on Tomcat server (in the startup. Bat configuration)

The set CATALINA_OPTS=- Xmx512m - Xms512m - Xmn64m Xss2m or

Set JAVA_OPTS=- Xmx512m - Xms512m Xmn64m - Xss2m

Set CATALINA_OPTS and JAVA_OPTS is a truth, at the time of start tomcat Settings,

Is the difference between JAVA_OPTS can execute this command in the tomcat stop,

3. Check the size of the heap

Unit of view in the program, the return value is a byte, of course there are other JVM parameters can be viewed,

The Runtime. GetRuntime (). MaxMemory ();


Or on the command line jvisualvm command

Or % java_home % \ bin directory click jvisualvm. The exe
Or on the command line jconsole command

Or % java_home % \ bin directory, click on the jconsole. The exe

4. Java heap memory can be divided into memory and the heap memory

- heap memory Settings: program can reach, can operate the
1/64 - Xms initial heap memory physical memory by default, is also a minimum heap memory, when the free heap memory is less than 40%, will rise to - the biggest limit Xms

-xmx maximum heap memory allocation physical memory by default, a quarter when free heap memory is more than 70%, will reduce to the minimum limit - Xms,
General Settings - Xms and Xms equal



- the heap memory Settings
- XX: PermSize than the initial value of heap memory, 1/64 of the default physical memory, is also a minimum of heap memory,
- XX: MaxPermSize maximum heap memory, 1/4 of the default physical memory,

5. Typical JVM parameter Settings:

Java - Xmx128m - Xms128m Xmn64m - Xss1m

- Xmx128m: set the JVM maximum available memory is 128 m,

Minimum - Xms128m: set the JVM memory is 128 m, this value can be set the same as the -xmx, every time to avoid recycling the JVM allocates memory again, after the completion of the

- Xmn2g: set the size of young generation to 2 g, the entire heap size=young generation size + old size + lasting generation size, generally lasting generation fixed size is 64 m, so increases after the young generation, will reduce the size of the old generation, the value of a greater influence on the performance of the system, 3/8 of the Sun's recommended configuration for the whole heap,

-xss128k: set the stack size of each thread, JDK5.0 after each thread stack size is 1 m, before each thread stack size is 256 k, according to the application thread required memory size adjustment, under the same physical memory, reduce this value can generate more threads, but the operating system on the number of threads within a process or limited, can not be infinite, experience value is controlled in 3000 ~ 5000,

Java - Xmx3550m - Xms3550m -xss128k - XX: XX: NewRatio option=4 - SurvivorRatio=4 - XX: MaxPermSize=16 m - XX: MaxTenuringThreshold=0

- XX: NewRatio option=4: set the young generation (including Eden and two Survivor area) and the ratio of old generation (excluding lasting generation), set to 4, the young generation and the older generation of ratio of 1:4, young generation accounts for 1/5 of the whole stack

- XX: SurvivorRatio=4: set the young generation in the Eden area and size ratio of the Survivor set to 4, the two Survivor area with an Eden area ratio for 2:4, a Survivor area accounts for 1/6 of the entire young generation

- XX: MaxPermSize=16 m: set the last generation size is 16 m,

- XX: MaxTenuringThreshold=0: set maximum age, garbage if set to 0, the young generation of objects without Survivor area, directly into the old generation,
  • Related