How JVM memory is set
The default Java Virtual Machine is small in size. When processing big data, Java reports an error: Java. Lang. outofmemoryerror.
The JVM memory setting method. For a separate. class, you can use the following method to set the JVM memory for test runtime.
Java-xms64m-xmx256m Test
-XMS is used to set the memory initialization size.
-Xmx is used to set the maximum memory available (it is best not to exceed the physical memory size)
In WebLogic, you can set the virtual memory size of each domain in startweblogic. cmd. The default setting is in commenv. cmd.
Address: http://cnpoint.com/framwwork/2006/1109/content_4563.htm
JVM Memory Optimization
1. Heap configuration and garbage collection Java heap are 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 |
Java heap maximum |
-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 does GC occur frequently in some programs? The program calls system. GC () or runtime. GC () for the following reasons (). 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 are frequently instantiated and 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-side JVM should set-XMS and-xmx to the same value. To optimize GC, it is recommended that the-xmn value be equal to 1/3 [2] of-xmx. 2. It is best for a GUI program to run GC every 10 to 20 seconds and complete GC every time within half a second [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.
-XSS |
Stack size of each thread |
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. For details about the four types of GC, refer to [3].
1. JVM tuning. http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp#garbage-collection2. Performance Tuning Java: tuning stepsleizhimin 51cto technology blog http://h21007.www2.hp.com/dspp/tech/tech_TechDocumentDetailPage_IDX/1,1701,1604,00.html
3. tuning garbage collection with the 1.4.2 javatm Virtual Machine. leizhimin 51cto technology blog http://java.sun.com/docs/hotspot/gc1.4.2/
Address: http://blog.csdn.net/tyrone1979/archive/2006/09/25/1274458.aspx
Address: http://cnpoint.com/framwwork/2006/1126/content_4669.htm