原博客地址: http://blog.csdn.net/huaye2007/article/details/21398429
最近沒什麼事,主要是看到程序GC較快 所以想看下程序有沒有問題,網上的一篇文章
http://book.51cto.com/art/201306/399236.htm
在程序啓動的時候加上 幾個參數
-verbose:gc -Xloggc:d:/gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
就會在控制檯打印gc的log 上面的鏈接有說明 ,我在這做下筆記。
660.353: [GC [PSYoungGen: 114944K->64K(115648K)] 411124K->296256K(1047744K), 0.0112058 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
675.030: [GC [PSYoungGen: 114944K->64K(115776K)] 411136K->296268K(1047872K), 0.0070017 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
689.634: [GC [PSYoungGen: 115136K->64K(115776K)] 411340K->296276K(1047872K), 0.0048806 secs] [Times: user=0.03 sys=0.00, real=0.00 secs]
704.105: [GC [PSYoungGen: 115136K->64K(115904K)] 411348K->296288K(1048000K), 0.0042253 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
718.741: [GC [PSYoungGen: 115328K->64K(115840K)] 411552K->296296K(1047936K), 0.0071211 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
733.365: [GC [PSYoungGen: 115328K->64K(115968K)] 411560K->296304K(1048064K), 0.0073260 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
747.959: [GC [PSYoungGen: 115520K->64K(115968K)] 411760K->296312K(1048064K), 0.0052526 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
660.353 虛擬機啓動以來的描述
GC 比較短暫的垃圾回收 fullgc就要注意了,對於時間延遲敏感的程序fullgc是個大問題。越少越好。
PSYoungGen 這個是根據你的GC收集器相關 我這是因爲我在虛擬機加了 -server 參數 導致虛擬機用了另外個一個GC收集器
114944K->64K(115648K) PSYoungGen在GC前後的內存變化 後面一個表示 PSYoungGen 的總大小
411124K->296256K(1047744K) java 堆在GC前後的變化 後面一個表示JAVA堆的總大小
在後面的就是GC消耗的時間了。
程序居然頻繁GC,最後從主邏輯開始註釋掉代碼查看,居然發現這樣的代碼居然有問題
- public class JavaS {
- public static void main(String[] args)
- {
- List<List<Integer>> dataList = new ArrayList<List<Integer>>();
- for(int i=0;i<5000;i++)
- {
- List<Integer> intList = new ArrayList<Integer>();
- dataList.add(intList);
- }
- while(true)
- {
- for(List<Integer> list : dataList)
- {
- for(Integer data : list)
- {
- System.out.println("=======");
- }
- //list.clear();
- }
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
一個ArrayList可能沒多少問題 但數量多上去 發現空值的時候 內存跳動太大了。