我写了一个简短的java程序来分配内存:
package com.company;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static final int SIZE_NATIVE_LONG_IN_BYTE = 8;
public static void main(String[] args) {
Integer memoryConsumptionInMiB = Integer.parseInt(args[0]);
List<long[][]> foo = new ArrayList<long[][]>();
int i = 0;
while (true) {
System.out.println(i++);
foo.add(new long[(1024 / SIZE_NATIVE_LONG_IN_BYTE * 1024)][memoryConsumptionInMiB]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试在具有几个不同参数的 docker 容器中运行它:
这就是我运行程序的方式(如果是 3):
(编辑:上传了上述类准备好的图像)
docker run -it --oom-kill-disable …Run Code Online (Sandbox Code Playgroud)