编写OOM程序 package com . example . demo ; import org . springframework . web . bind . annotation . GetMapping ; import org . springframework . web . bind . annotation . RestController ; import java . util . ArrayList ; @RestController
编写OOM程序
package com.example.demo;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
public class TestController {
("/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;
public class Demo1111Application {
public static void main(String[] args) {
SpringApplication.run(Demo1111Application.class, args);
}
}
启动SpringBoot项目
使用Java VisualVM工具监视监控JVM情况
开始访问接口,等待OOM异常
http://localhost:8080//hello
打开dump文件
OOM情况
这里还显示在Java代码的哪行