Case 1: java.lang.OutOfMemoryError: Java heap space
Reason: Java heap memory is insufficient, it may be really insufficient, or there may be an infinite loop in the program
Solution: 1. Adjust JVM parameters -Xms2048m -Xmx2048m
2. Locate the infinite loop code
Case 2: java.lang.OutOfMemoryError: GC overhead limit exceeded
Reason: JDK6 adds a new error type, which is thrown when the GC takes a lot of time to release a small space; generally because the heap is too small, resulting in an exception, there is not enough memory
Solution: 1. Check whether there is code that uses large memory or an infinite loop in the system
2. Add jvm parameter configuration to limit the use of memory: -XX:-UseGCOverheadLimit
Case 3: java.lang.OutOfMemoryError: PermGen space
Reason: Insufficient memory in Perm area
方案:-XX:MaxPermSize=128m -XX:PermSize=128m
Case 4: java.lang.OutOfMemoryError: Direct buffer memory
Reason: Adjust -XX:MaxDirectMemorySize= parameter
Scheme: -XX:MaxDirectMemorySize=128m
情况五:java.lang.OutOfMemoryError: unable to create new native thread
Reason: The stack space is not enough to create additional threads, either too many threads are created, or the stack space is really small
Solution: Since the JVM does not provide parameters to set the total stack space size, it can set the size of a single thread stack; while the user space of the system is 3G in total, except for the Text/Data/BSS/MemoryMapping segments, Heap and Stack space The total amount is limited, and it is one change and another grows. Therefore, if you encounter this error, you can solve it in two ways: 1. Reduce the stack size of a single thread through the -Xss startup parameter, so that more threads can be opened (of course, it cannot be too small, and a StackOverflowError will appear); 2. Through- The two parameters of Xms -Xmx reduce the size of the heap and give the memory to the stack (provided that the heap space is sufficient)
Case 6: java.lang.StackOverflowError
Reason: This is also a type of memory overflow error, that is, the overflow of the thread stack, either because there are too many method calls (such as infinite recursive calls), or the thread stack is too small
Solution: optimize program design, reduce method call level; adjust -Xss parameter to increase thread stack size