一、People
public class People {
private Integer id;
private String name;
private Integer age;
private String job;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void print(){
System.out.println("我是print本人");
}
}
二、测试
/**
* 案例1:模拟线上环境OOM
*/
@GetMapping("/add")
public void addObject(){
System.err.println("add"+peopleSevice);
ArrayList<People> people = new ArrayList<>();
while (true){
people.add(new People());
}
}
三、参数设置
常用参数
-XX:+PrintGCDetails
-XX:MetaspaceSize=64m
-Xss512K
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=heap/heapdump3.hprof
-XX:SurvivorRatio=8
-XX:+PrintGCDateStamps
-Xms80M
-Xmx80M
-Xloggc:log/gc-oom3.log
1、设置内存
-Xms80M
-Xmx80M
2、输出GC打印
-XX:+PrintGCDetails
image.png
java.lang.OutOfMemoryError: Java heap space.png
2022-04-29T13:48:53.158-0800: [GC (Allocation Failure) [PSYoungGen: 5632K->609K(11264K)] 15448K->10426K(45568K), 0.0027678 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
Disconnected from the target VM, address: '127.0.0.1:61538', transport: 'socket'
2022-04-29T13:49:29.950-0800: [GC (Allocation Failure) [PSYoungGen: 6241K->673K(11264K)] 16058K->10727K(45568K), 0.0201017 secs] [Times: user=0.01 sys=0.00, real=0.02 secs]
2022-04-29 13:49:29.997 INFO 47978 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
Heap
PSYoungGen total 11264K, used 1002K [0x00000007bef80000, 0x00000007c0000000, 0x00000007c0000000)
eden space 5632K, 5% used [0x00000007bef80000,0x00000007befd20f0,0x00000007bf500000)
from space 5632K, 11% used [0x00000007bfa80000,0x00000007bfb287c8,0x00000007c0000000)
to space 5632K, 0% used [0x00000007bf500000,0x00000007bf500000,0x00000007bfa80000)
ParOldGen total 34304K, used 10053K [0x00000007bce00000, 0x00000007bef80000, 0x00000007bef80000)
object space 34304K, 29% used [0x00000007bce00000,0x00000007bd7d1598,0x00000007bef80000)
Metaspace used 34745K, capacity 36868K, committed 37424K, reserved 1081344K
class space used 4642K, capacity 5032K, committed 5168K, reserved 1048576K
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
3、输出日志
-Xloggc:log/gc-oom3.log
4、生成Dump文件
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=heap/heapdump3.hprof
网友评论