赞
踩
先写一个堆溢出的程序:
package com.lchtest; import java.util.ArrayList; import java.util.List; public class JvmSizeTest { public void testHeap(){ //堆溢出 List<byte[]> list = new ArrayList<>(); int i=0; while (true){ list.add(new byte[5*1024*1024]); // System.out.print("count is: "+(++i)); } } int num = 1; public void testStack(){ //栈溢出 num++; this.testStack(); } public static void main(String[] args) { long max = Runtime.getRuntime().maxMemory(); long total = Runtime.getRuntime().totalMemory(); System.out.println("max:" + (double) max/1024/1024 + "MB");
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。