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

虚拟机栈

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

方法区

运行时常量池

posted @ 2016-06-22 21:42  清泉白石  阅读(290)  评论(0编辑  收藏  举报