设为首页 加入收藏

TOP

Java垃圾收集器之Serial收集器(二)
2015-02-02 14:17:06 来源: 作者: 【 】 浏览:13
Tags:Java 垃圾 收集器 Serial
043d0000)


?from space 1024K,? 93% used[0x043d0000, 0x044c00f0, 0x044d0000)


?to? space 1024K,? 0% used [0x044d0000, 0x044d0000, 0x045d0000)


?tenured generation? total 20480K, used 20436K [0x045d0000,0x059d0000, 0x059d0000)


? the space 20480K,? 99% used[0x045d0000, 0x059c52b8, 0x059c5400, 0x059d0000)


?compacting perm gen? total 12288K, used 2105K [0x059d0000,0x065d0000, 0x099d0000)


? …


GC [DefNew :是在新生代的回收,能够很清楚的看到新生代的空间被迅速用完。


Full GC [Tenured是在老年代的全GC回收,空间也很快用完,然后出现OutOfMemoryError错误,导致系统崩溃。


?


5、代码和示例(可扩展JAVA虚拟机大小)


package com.gc;


?


import java.util.ArrayList;


import java.util.List;


?


/**


?* 简单的JAVA虚拟机内存回收,serial收集器的使用


?* 参数:-Xms30m -Xmx30m-Xmn10m -XX:+UseSerialGC -XX:+PrintGCDetails


?* @author 范芳铭


?*/


public class EasySerial {


? ? ? public byte[] placeHolder =new byte[64 * 1024]; //占位符


? ? ? public static voidmain(String[] args) throws Exception{


? ? ? ? ? ? ? outOfMemoryByExpansionSize();


? ? ? }


? ? ?


? ? ? /**


? ? ? ? * 固定JAVA虚拟机的大小


? ? ? ? * 参数:-Xms30m -Xmx30m-Xmn10m -XX:+UseSerialGC -XX:+PrintGCDetails


? ? ? ? * @author 范芳铭


? ? ? ? */


? ? ? private static voidoutOfMemoryByFixSize() throws Exception{


? ? ? ? ? ? ? Listlist = new ArrayList();


? ? ? ? ? ? ? while(true){


? ? ? ? ? ? ? ? ? ? EasySerialserial = new EasySerial();


? ? ? ? ? ? ? ? ? ? list.add(serial);


? ? ? ? ? ? ? ? ? ? Thread.sleep(10);//停顿10毫秒


? ? ? ? ? ? ? }


? ? ? }


? ? ?


? ? ? /**


? ? ? ? * JAVA虚拟机的大小适当可扩展,其中Xms30m,Xmx40m


? ? ? ? * 参数:-Xms30m -Xmx40m-XX:+UseSerialGC -XX:+PrintGCDetails


? ? ? ? * @author 范芳铭


? ? ? ? */


? ? ? private static voidoutOfMemoryByExpansionSize() throws Exception{


? ? ? ? ? ? ? Listlist = new ArrayList();


? ? ? ? ? ? ? while(true){


? ? ? ? ? ? ? ? ? ? EasySerialserial = new EasySerial();


? ? ? ? ? ? ? ? ? ? list.add(serial);


? ? ? ? ? ? ? ? ? ? Thread.sleep(10);//停顿10毫秒


? ? ? ? ? ? ? }


? ? ? }


}


参数:-Xms30m -Xmx30m-Xmn10m -XX:+UseSerialGC -XX:+PrintGCDetails


-XX:+UseSerialGC的是Serial收集器,Xms30m –Xmx40m 指定了JAVA虚拟机的大小可以从30M提升到40M,没有强制指定JAVA新生代的空间大小。


运行后情况:


[GC [DefNew: 1986K->128K(2112K),0.0011191 secs] 27809K->27808K(30528K), 0.0011425 secs] [Times: user=0.00sys=0.01, real=0.00 secs]


[GC [DefNew: 1989K->131K(2112K),0.0011326 secs][Tenured: 29536K->29539K(29568K), 0.0032603 secs]29669K->29667K(31680K), [Perm : 2086K->2086K(12288K)], 0.0044714 secs][Times: user=0.00 sys=0.00, real=0.00 secs]


[GC [DefNew: 2562K->192K(2880K),0.0024077 secs] 32102K->32100K(40704K), 0.0024426 secs] [Times: user=0.00sys=0.00, real=0.00 secs]


[GC [DefNew: 2755K->192K(2880K),0.0015362 secs] 34663K->34662K(40704K), 0.0015731 secs] [Times: user=0.00sys=0.00, real=0.00 secs]


[GC [DefNew: 2755K->192K(2880K),0.0015842 secs] 37224K->37223K(40704K), 0.0016187 secs] [Times: user=0.00sys=0.00, real=0.00 secs]


[GC [DefNew: 2755K->2755K(2880K),0.0000144 secs][Tenured: 37030K->37799K(37824K), 0.0039907 secs]39786K->39784K(40704K), [Perm : 2086K->2086K(12288K)], 0.0040547 secs][Times: user=0.00 sys=0.00, real=0.00 secs]


[Full GC [Tenured:37799K->37799K(37824K), 0.0032501 secs] 40554K->40553K(40704K), [Perm :2086K->2086K(12288K)], 0.0032940 secs] [Times: user=0.00 sys=0.00, real=0.00secs]


[Full GC [Tenured:37799K->37792K(37824K), 0.0107478 secs] 40553K->40546K(40704K), [Perm :2086K->2084K(12288K)], 0.0107782 secs] [Times: user=0.02 sys=0.00, real=0.01secs]


Exception in thread "main"java.lang.OutOfMemoryError: Java heap space


? ? atcom.gc.EasySerial.(EasySerial.java:12)


? ? atcom.gc.EasySerial.outOfMemoryByExpansionSize(EasySerial.java:39

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java垃圾收集器之ParNew收集器 下一篇线上性能检测工具之Btrace

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: