As we all know, JVM memory is limited. One is the system architecture of the machine, and the other is the operating system itself.
The memory ing between x86, x86-64, or iSCSI,... is different, and the memory management mechanisms of various operating systems are also different.
The following are Java heap settings from http://fengyouhua.javaeye.com/blog/58170 1. Heap and garbage collection divided into three zones, young, old and permanent. Young stores the just-instantiated object. When the area is filled up, GC moves the object to the old area. The permanent area stores the reflection object. This section does not discuss this area. JVM heap allocation can be set using the-x parameter,
| -XMS |
initial heap size |
| -xmx |
maximum Java heap value |
| -xmn |
heap size of young generation |
JVM has two GC threads. The first thread is responsible for revoking heap's young zone. When the heap is insufficient, the second thread traverses the heap and upgrades the young area to the older area. The size of the older area is equal to-xmx minus-xmn, and the value of-XMS cannot be set too large, because the second thread is forced to run will reduce JVM performance. Why?
Program Frequent GC? There are the following reasons:
L The program calls system. GC () or runtime. GC ().
L Some middleware software calls their own GC methods. In this case, you need to set parameters to disable these GC methods.
L Java heap is too small. Generally, the default heap value is very small.
L Objects that are frequently instantiated are release objects. In this case, try to save and reuse objects, for example, using stringbuffer () and string (). If you find that after each GC, the remaining heap space will be 50% of the total space, which indicates that your heap is healthy. Many Java programs on the server end have a better free space of 65% after each GC. Experience:
1 . Server End JVM It is best -XMS And -Xmx Set to the same value. To optimize GC , It is best to make -Xmn The value is approximately equal -Xmx Of 1/3 [2] . 2 . One Gui The program is best per 10 To 20 Run Once in seconds GC , Completed in half a second each time [2] . Note: 1. Increasing the heap size reduces the GC frequency, but also increases the GC time. When GC is run, all user threads are paused, that is, Java applications do not work during GC. 2. The heap size does not determine the memory usage of the process. The memory usage of a process must be greater than the value defined by-xmx, Because Java allocates memory for other tasks, such as the stack of each thread. 2. stack settings each thread has its own stack.
The stack size limits the number of threads. If the stack is too large, the memory may leak. -The XSS parameter determines the stack size, for example,-xss1024k. If the stack is too small, the stack may leak. 3. The hardware environment also affects GC efficiency, such as the machine type, memory, swap space, and number of CPUs. If your program needs to frequently create many transient objects, this will lead to frequent jvm gc. In this case, you can increase the machine memory to reduce the use of swap space [2]. The first type of GC is single-thread GC, which is also the default GC ., This GC is applicable to single-CPU machines. The second type is throughput GC, which is a multi-thread GC. It is suitable for programs with multiple CPUs and a large number of threads. The second type of GC is similar to the first type of GC. The difference is that the GC is multi-threaded in the young area, but in the old area and the first one, the single thread is still used. -XX: + useparallelgc parameter to start the GC. The third type is concurrent low pause GC, which is similar to the first type. It is suitable for multiple CPUs and requires shorter time for program stagnation caused by GC. This GC can be used to run applications in the old zone. -XX: + useconcmarksweepgc parameter to start the GC. The fourth type is incremental low pause GC, which is applicable to the requirement to shorten the time of program stagnation caused by GC. This GC can be used to reclaim some old objects in the young area. -The xincgc parameter starts the GC.