1.-Xms堆最小容量 -Xmx堆最大得容量,一般都设置成一样的
java -Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError HeapOOM
import java.util.ArrayList;
import java.util.List;
public class HeapOOM {
static class OOMObject{
}
public static void main(String[] args) {
List<OOMObject> list = new ArrayList<OOMObject>();
while (true) {
list.add(new OOMObject());
}
}
}
2.-Xss减少栈内存容量
java -Xss128k JavaVMStackEOF
public class JavaVMStackEOF {
private static int stackLengh=1;
public void stackMethod(){
stackLengh++;
this.stackMethod();
}
public static void main(String[] args) {
JavaVMStackEOF j = new JavaVMStackEOF();
try {
j.stackMethod();
} catch (Throwable e) {
System.out.println("stack length: "+stackLengh);
}
}
}
java -Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError HeapOOM
import java.util.ArrayList;
import java.util.List;
public class HeapOOM {
static class OOMObject{
}
public static void main(String[] args) {
List<OOMObject> list = new ArrayList<OOMObject>();
while (true) {
list.add(new OOMObject());
}
}
}
2.-Xss减少栈内存容量
java -Xss128k JavaVMStackEOF
public class JavaVMStackEOF {
private static int stackLengh=1;
public void stackMethod(){
stackLengh++;
this.stackMethod();
}
public static void main(String[] args) {
JavaVMStackEOF j = new JavaVMStackEOF();
try {
j.stackMethod();
} catch (Throwable e) {
System.out.println("stack length: "+stackLengh);
}
}
}