Infra Structure/WAS
[Tomcat] OutOfMemory 강제 발생
하 선생
2021. 8. 18. 00:29
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/