java gc的log分析

原博客地址: 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,最後從主邏輯開始註釋掉代碼查看,居然發現這樣的代碼居然有問題

[java] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. public class JavaS {  
  2.   
  3.     public static void main(String[] args)  
  4.     {  
  5.         List<List<Integer>> dataList = new ArrayList<List<Integer>>();  
  6.         for(int i=0;i<5000;i++)  
  7.         {  
  8.             List<Integer> intList = new ArrayList<Integer>();  
  9.             dataList.add(intList);  
  10.         }  
  11.           
  12.         while(true)  
  13.         {  
  14.             for(List<Integer> list : dataList)  
  15.             {  
  16.                 for(Integer data : list)  
  17.                 {  
  18.                     System.out.println("=======");  
  19.                 }  
  20.                 //list.clear();  
  21.             }  
  22.             try {  
  23.                 Thread.sleep(1);  
  24.             } catch (InterruptedException e) {  
  25.                 // TODO Auto-generated catch block  
  26.                 e.printStackTrace();  
  27.             }  
  28.         }  
  29.     }  
  30. }  

一個ArrayList可能沒多少問題  但數量多上去  發現空值的時候  內存跳動太大了。
發佈了55 篇原創文章 · 獲贊 5 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章