String的intern()步骤
String的intern()方法
public class StringTest { public static void main(String[] args) { for (long i = 0; i < 10000000000000L; i++) { // 1. // new String(i+""); // 2. new String(i + "").intern(); } } }
jstat看到的结果
运行1 perm区没有变化,不停的进行young gc
运行2 intern方法往常量区放数据,使perm区一直在增长,younggc不是很频发
full gc可以回收掉常量池中的数据