标签:
public static void stackOverFlow(){ stackOverFlow(); }
static class TestBean{}
/**
*
* 堆溢出 Java heap space
*/
public static void outOfMemory(){
try {
while (true){
list.add( new TestBean());
}
}catch (Exception e){
System.out.println(e);
}
}
static List arrayList=new ArrayList();
public static void outOfMemoryPremGen(){
int i=0;
while (true){
list.add(String.valueOf(i++).intern());
}
}
Unsafe 分配堆外内存(java nio就是这样实现)
//Unsafe 分配内存
private static final Unsafe unsafe = Unsafe.getUnsafe();
private final static int size=1024*1024;
public static void getSyseMmory(){
while (true){
unsafe.allocateMemory(size);
}
}
标签:
原文地址:http://www.cnblogs.com/xbgfy/p/5725585.html