項目中遇到一個問題求教CSDN大牛們,在大批量創建Arraylist的過程中發現GC overhead limit exceeded的情況,具體情況簡化如下。
項目中需要用Arraylist添加1000000次counter_temp字符串,counter_temp字符串需要100次累加得到。在運行到後期會出現GC overhead limit exceeded的情況,求大牛指點迷津,怎麼修改可以解決。代碼簡化如下:
import java.util.ArrayList;
public class TestGC {
public static void main(String[] args) {
ArrayList list = new ArrayList();
String counter_temp=null;
for (int i = 0; i < 1000000; i++) {
long s = System.currentTimeMillis();
for (int j = 0; j < 100; j++){
if (counter_temp==null){
counter_temp="1";
}else{
counter_temp=counter_temp+"$1";
}
}
list.add(counter_temp);
long end = System.currentTimeMillis();
System.out.println(end-s);
}
}
}
http://blog.csdn.net/flyingqr/article/details/9170361