/**
* Copyright description
*/
package overload;
import java.util.HashSet;
/**
* To Add descript here
*测试outMemory是否可以捕捉
* @author think
* @since 2012-1-14
*/
public class OutMemory {
/**
* Methods description
*
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long t = 0;
try{
HashSet total = new HashSet(1000000);
for(;;){
System.out.println("["+(t++)+"]");
HashSet ss = new HashSet(1000000);
ss.add(new Object());
total.add(ss);
}
}catch(Exception e){
e.printStackTrace();
}
}
}
平台打印的东东
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.HashMap.<init>(Unknown Source)
at java.util.HashMap.<init>(Unknown Source)
at java.util.HashSet.<init>(Unknown Source)
at overload.OutMemory.main(OutMemory.java:28)
事实证明可以被捕捉的
检测OutOfMemoryError是否可以被捕捉
最新推荐文章于 2025-07-01 16:42:03 发布