Situation one: Java.lang.OutOfMemoryError:Java heap space
Cause: The Java heap is running out of memory, may be really inadequate, or it may be a dead loop in the program
Scenario: 1, Tuning JVM parameters-xms2048m-xmx2048m
2. Locating the Dead Loop code
Scenario Two: Java.lang.OutOfMemoryError:GC overhead limit exceeded
Cause: JDK6 adds a new error type that is thrown when the GC is taking a lot of time to free up a small space, usually because the heap is too small to cause an exception, not enough memory
Scenario: 1. Check the system for any code that uses large memory or a dead loop
2, add the JVM parameter configuration, to limit the use of memory:-xx:-usegcoverheadlimit
Scenario Three: Java.lang.OutOfMemoryError:PermGen space
Cause: Insufficient memory in the Perm area
Scenario:-xx:maxpermsize=128m-xx:permsize=128m
Situation four: Java.lang.OutOfMemoryError:Direct buffer memory
Reason: Adjust the-xx:maxdirectmemorysize= parameter
Scenario:-xx:maxdirectmemorysize=128m
Scenario Five: Java.lang.OutOfMemoryError:unable to create new native thread
Cause: Stack space is not enough to create additional threads, either too many threads are created, or the stack space is really small
Scenario: Because the JVM does not provide parameters to set the total stack space size, but can set the size of a single line stacks, and the system's user space is a total of 3G, in addition to text/data/bss/memorymapping a few paragraphs, heap and stack space is limited, It is the one that has been eliminated. Therefore, there are two ways to solve this error: 1. Reduce the size of a single thread stack by-XSS startup parameters, so that more threads can be opened (not too small, too small to appear stackoverflowerror), 2. Reduce the heap size by-xms-xmx two parameters, Give the memory to the stack (provided that the heap space is sufficient)
Situation VI: Java.lang.StackOverflowError
Cause: This is also a memory overflow error, that is, the overflow of the line stacks, either the method call hierarchy too many (such as there is an infinite recursive call), or the line stacks is too small
Program: Optimize the program design, reduce the method call level; Adjust the-XSS parameter to increase the thread stack size
Several scenarios where memory overflow occurs in Java