jvm_outofmemory_

package cn.itcast_03_jvm.outofmemory;


import java.lang.reflect.Field;


import sun.misc.Unsafe;


/**
 * 本機直接內存溢出
 * VM Args:-Xmx20M -XX:MaxDirectMemorySize=10M
 */
public class DirectMemoryOOM {
private static final int _1MB = 1024 * 1024;


public static void main(String[] args) throws Exception {
Field unsafeField = Unsafe.class.getDeclaredFields()[0];
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);
while (true) {
unsafe.allocateMemory(_1MB);
}
}
}package cn.itcast_03_jvm.outofmemory;


import java.lang.reflect.Field;


import sun.misc.Unsafe;


/**
 * 本機直接內存溢出
 * VM Args:-Xmx20M -XX:MaxDirectMemorySize=10M
 */
public class DirectMemoryOOM {
private static final int _1MB = 1024 * 1024;


public static void main(String[] args) throws Exception {
Field unsafeField = Unsafe.class.getDeclaredFields()[0];
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);
while (true) {
unsafe.allocateMemory(_1MB);
}
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章