虚拟机栈

将栈的大小设置为-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

方法区

运行时常量池

关于作者

后端程序员,五年开发经验,从事互联网金融方向。技术公众号「清泉白石」。如果您在阅读文章时有什么疑问或者发现文章的错误,欢迎在公众号里给我留言。

Java虚拟机(二) —— 运行时数据区的OOM异常

相关文章:

  • 2021-10-19
  • 2021-07-17
  • 2021-11-15
  • 2021-12-30
猜你喜欢
  • 2021-06-11
  • 2021-09-12
  • 2021-04-03
  • 2021-05-09
相关资源
相似解决方案