OutOfMemoryError

以下的这段代码应该是报错的才对,但是我在运行了之后,程序一直卡在那里。最后请教老师了解到,原来jvm如果不指定运行参数,是会进行自动扩容的。

package com.coding.jvm.oom;

public class NativeErrorDemo {
    public static void main(String[] args) {

        for (; ; ) {
            new Thread(() -> {
                try {
                    Thread.sleep(Integer.MAX_VALUE);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }

    }
}

于是,在运行这段代码之前,我手动指定了以下内存大小。

最后,运行之,达到了自己想要模拟的结果:

posted on   ~码铃薯~  阅读(11)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
历史上的今天:
2021-05-18 The web application [ROOT] appears to have started a thread named [logback-1] but has failed to stop
2020-05-18 '�й� You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support. -> [Help 1]
2020-05-18 You must configure either the server or JDBC driver (via the serverTimezone conf)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示