内存溢出示例
@RestController
public class DemoController {
List<User> userList = new ArrayList<>();
List<Class<?>> classList = new ArrayList<>();
/**
* -Xmx32M -Xms32M
* @return
*/
@GetMapping("/heap")
public String heap() {
int i = 0;
while (true) {
userList.add(new User(i++, UUID.randomUUID().toString()));
}
}
/**
* -XX:MetaspaceSize=32M -XX:MaxMetaspaceSize=32M
* @return
*/
@GetMapping("/nonheap")
public String nonHeap() {
while (true) {
classList.addAll(Metaspace.createClasses());
}
}
}
Exception in thread "Catalina-utility-2" Exception in thread "http-nio-8088-exec-1" java.lang.OutOfMemoryError: GC overhead limit exceeded
java.lang.OutOfMemoryError: GC overhead limit exceeded
- 触发Metaspace溢出:http://localhost:8088/nonheap
Exception in thread "main" java.lang.OutOfMemoryError: Metaspace