编写OOM程序
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
@RestController
public class TestController {
@GetMapping("/hello")
public void c_() throws InterruptedException {
System.out.println("你好");
Integer K = 1024000000;
ArrayList<byte[]> list = new ArrayList<>();
int i = 0;
while (true) {
Thread.sleep(50);
list.add(new byte[5 * 1024 * 1024]);
System.out.println("分配次数" + (++i));
}
}
}
启动类 , 名字瞎起的,不要在意细节
package com;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Demo1111Application {
public static void main(String[] args) {
SpringApplication.run(Demo1111Application.class, args);
}
}
启动SpringBoot项目
使用Java VisualVM工具监视监控JVM情况
jvisualvm具体使用看下面两个链接,等我有时间再整理整理
https://www.cnblogs.com/mzq123/p/11166640.html
https://blog.csdn.net/shuai825644975/article/details/78970371
开始访问接口,等待OOM异常
http://localhost:8080//hello
用MAT插件打开dump文件
打开dump文件需要安装Eclipse MAT(Memory Analyzer) 插件:
下面是安装方式
https://blog.csdn.net/qq_41489540/article/details/113794280
OOM情况
这里还显示在Java代码的哪行