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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章