原博客地址: 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可能没多少问题 但数量多上去 发现空值的时候 内存跳动太大了。