Example 1
import java.util.ArrayList; import java.util.List; class SimulateOutOfMemory { public static void main(String[] args) { List<byte[]> list = new ArrayList<>(); int index = 1; while (true) { // 1MB each loop, 1 x 1024 x 1024 = 1048576 byte[] b = new byte[1048576]; list.add(b); Runtime rt = Runtime.getRuntime(); System.out.printf("[%d] free memory: %s%n", index++, rt.freeMemory()); } } }
Example 2
import java.util.ArrayList; class SimulateOutOfMemory { public static void main(String[] args) { new ArrayList(Integer.MAX_VALUE); } }
[출처]https://codechacha.com/ko/java-simulate-out-of-memery-error/
'Infra Structure > WAS' 카테고리의 다른 글
[Tomcat] 서버 정보 노출 방지 (0) | 2021.08.20 |
---|---|
[Tomcat] SSL 적용하기 (0) | 2021.08.19 |
[Tomcat] 톰캣 실행여부 확인 및 시작 Shell Script (0) | 2021.08.17 |
[Tomcat]OutOfMemory시 자동 힙덤프, 톰캣 자동 재시작 (1) | 2021.08.17 |
[crontab]Tomcat 자동 재시작 (0) | 2021.08.17 |