虚拟机栈
将栈的大小设置为-Xss160k
public class TestStackOom {
public static void main(String[] args) {
List<Thread> list = new ArrayList<>();
Thread t = null;
for (int i = 1; i <= 1000000; i++) {
t = new Thread(() -> {
try {
Thread.sleep(100_0000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
list.add(t);
System.out.println("执行线程"+t.getName());
t.start();
}
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("任务完成");
}
}
运行的结果,出现OOMError:unable to create new native thread