3 回答

TA貢獻1784條經驗 獲得超7個贊
要創建OutOfMemoryError: Metaspace使用javassist.ClassPool庫。下面的示例將創建Metaspace錯誤。
import javassist.ClassPool;
public class OutOfMemoryErrorMetaspace {
//ClassPool objects hold all the CtClasses.
static ClassPool classPool = ClassPool.getDefault();
public static void main(String[] args) throws Exception {
for (int i = 0; i < 1000000; i++) {
//makeClass method - Creates a new class (or interface) from the given class file.
Class clas = classPool.makeClass(
i + " outofmemory.OutOfMemoryErrorMetaspace ").toClass();
//Print name of class loaded
System.out.println(clas.getName());
}
}
}
添加回答
舉報