One , Stack overflow (StackOverflowError)

The stack is thread private , His life cycle is the same as threads , Each method creates a stack frame when it is executed , Used to store the local variable table , Operands stack , dynamic link , Method exit light information . The local variable table also contains the basic data types , Object reference type ( Local variable table compiler complete , It does not change during operation )

So we can understand that stack overflow is that the stack frame created by method execution exceeds the depth of stack . Most likely, then, is that recursive method calls produce this result .
public class JvmTest { private int i = 0; public void a(){
System.out.println(i++); a(); } public static void main(String[] args) {
JvmTest j = new JvmTest(); j.a(); } }
Output results :

How to solve this problem :

We need to use parameters -Xss To adjust JVM Stack size

The effect is as follows

But you need to be aware of the risks of recursive programs .

Two , Heap overflow (OutOfMemoryError:java heap space)

heap space Represents heap space , Objects are mainly stored in the heap . If it continues new Object causes space overflow in the heap
public class JvmTest { public static void main(String[] args) { List<String>
aList = new ArrayList<String>(); try{ while(true){ aList.add("asdasdasdas"); }
}catch(Throwable e){ System.out.println(aList.size()); e.printStackTrace(); } }
Abnormal information :

It can be done through  -Xmx4096M Adjust the total size of the heap

Three , Permanent generation overflow (OutOfMemoryError: PermGen space)

because JDK7,8 Remove permanent belt , So the above code is in JDK1.6 There will be a permanent overflow in the case of .


©2019-2020 Toolsou All rights reserved,
QQ Login interface implementation code implementation mysql Addition, deletion, modification and query of database JAVA Experiment 4 set and functional programming experiment about String How to create objects VHDL——4 choose 1 Data selector C language ( Guess numbers games ) Blue Bridge Cup MCU advanced module --NE555 I don't memorize eight part essays , You go to the interview ? Hill sorting of sorting algorithm ——c++ realization python What does built-in function mean _python What are the built-in functions