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());
}
}
}
添加回答
举报