1, StackOverflow:
Whenever a Java program launches a new thread, the Java virtual Opportunity allocates a stack for him, and the Java stack keeps the thread running in frames, and when the thread calls a method, the JVM presses a new stack frame into the thread's stack, and the stack frame exists as long as the method does not return.
If a method has too many nested call hierarchies (such as recursive calls), as the number of frames in the Java stack increases, the sum of all the stack frames in the stack of the thread will eventually be greater than the value set by the-XSS, resulting in a raw stackoverflowerror overflow exception.
2, OutOfMemory:
2.1, Stack memory overflow
When a Java program launches a new thread, there is not enough space to allocate the Java stack for the thread, the size of the Java stack is determined by the-XSS setting, and the JVM throws a OutOfMemoryError exception.
2.2. Heap Memory Overflow
The Java heap is used to hold an instance of an object, and throws an OutOfMemoryError exception when it is necessary to allocate memory for an instance of an object, while the heap occupies the maximum value set (via-xmx) to set the maximum value.
2.3. Method Area Memory Overflow
The method area is used to store information about Java classes, such as class names, access modifiers, Chang, field descriptions, method descriptions, and so on. When the class loader loads the class file into memory, the JVM extracts the information from the classes and puts the class information in the method area.
When these class information needs to be stored and the memory footprint of the method area has reached its maximum (via-xx:maxpermsize), the basic idea is that the OutOfMemoryError exception will be thrown to the test of this situation, and the fundamental thought is that the runtime generates a large number of classes to fill the method area until it overflows. There are a lot of dynamic classes that need to be run with Cglib directly to manipulate bytecode.
Transferred from: http://blog.csdn.net/chenchaofuck1/article/details/51144223
Java Stackoverflowerror and OutOfMemoryError differences (RPM)