jvm_book/src/org/fenixsoft/jvm/chapter2/RuntimeConstantPoolOOM_1.java
ZhouZhiming 10c303de60 init
init
2019-12-24 11:11:01 +08:00

23 lines
554 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package org.fenixsoft.jvm.chapter2;
import java.util.HashSet;
import java.util.Set;
/**
* VM Args-XX:PermSize=6M -XX:MaxPermSize=6M
*
* @author zzm
*/
public class RuntimeConstantPoolOOM_1 {
public static void main(String[] args) {
// 使用Set保持着常量池引用避免Full GC回收常量池行为
Set<String> set = new HashSet<String>();
// 在short范围内足以让6MB的PermSize产生OOM了
short i = 0;
while (true) {
set.add(String.valueOf(i++).intern());
}
}
}