Java垃圾收集器之Parallel Old收集器

Parallel Old收集器是Java虚拟机中垃圾收集器的一种。和Serial Old收集器一样,工作在JAV虚拟机的老年代。这种垃圾收集器使用多线程和“标记-整理”算法。它在JDK 1.6中才开始提供。

在注重吞吐量及CPU资源敏感的场合,都可以优先考虑Parallel Scavenge加Parallel Old收集器。

1、运行代码

package com.gc;

import java.util.ArrayList;

import java.util.List;

/**

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

* 参数:-Xms30m -Xmx60m-Xmn10m -XX:+UseParallelOldGC -XX:+PrintGCDetails

* @author 范芳铭

*/

public class EasyParallelOld {

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

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

outOfMemoryByExpansionSize();

}

private static voidoutOfMemoryByExpansionSize() throws Exception{

List<EasyParallelOld>list = new ArrayList<EasyParallelOld>();

while(true){

EasyParallelOldserial = new EasyParallelOld();

list.add(serial);

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

}

}

}

2、参数

-Xms30m -Xmx60m -Xmn10m -XX:+UseParallelOldGC -XX:+PrintGCDetails

-Xms30m  JVM最小30M

-Xmx100m  JVM最大100M

-Xmn10m  新生代固定10M

-XX:+ UseParallelOldGC对应parallel scavenge +parallel old 收集器

-XX:+PrintGCDetails 打印详细GC

3、运行结果

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 50664K->50664K(51200K)]54058K->54058K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0043610 secs][Times: user=0.00 sys=0.00, real=0.00 secs]

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 50728K->50728K(51200K)]54122K->54122K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0071480 secs][Times: user=0.00 sys=0.00, real=0.01 secs]

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 50792K->50792K(51200K)]54186K->54186K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0061676 secs][Times: user=0.00 sys=0.00, real=0.01 secs]

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 50856K->50856K(51200K)]54250K->54250K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0047575 secs][Times: user=0.00 sys=0.00, real=0.00 secs]

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 50920K->50920K(51200K)]54314K->54314K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0044603 secs][Times: user=0.00 sys=0.00, real=0.00 secs]

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 50984K->50984K(51200K)]54378K->54378K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0041311 secs][Times: user=0.00 sys=0.00, real=0.00 secs]

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 51048K->51048K(51200K)]54442K->54442K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0042710 secs][Times: user=0.00 sys=0.00, real=0.00 secs]

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 51112K->51112K(51200K)]54506K->54506K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0044147 secs][Times: user=0.00 sys=0.00, real=0.00 secs]

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 51176K->51176K(51200K)]54570K->54570K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0044082 secs][Times: user=0.00 sys=0.00, real=0.00 secs]

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 51176K->51176K(51200K)]54570K->54570K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0044738 secs][Times: user=0.00 sys=0.00, real=0.01 secs]

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

atcom.gc.EasyParNew.<init>(EasyParNew.java:12)

atcom.gc.EasyParNew.outOfMemoryByExpansionSize(EasyParNew.java:39)

atcom.gc.EasyParNew.main(EasyParNew.java:14)

Heap

PSYoungGen    total 6848K, used 3456K [0x0ad30000, 0x0b730000, 0x0b730000)

eden space 3456K, 100% used [0x0ad30000,0x0b090000,0x0b090000)

from space 3392K, 0% used [0x0b090000,0x0b090000,0x0b3e0000)

to  space 3392K, 0% used[0x0b3e0000,0x0b3e0000,0x0b730000)

ParOldGen      total 51200K, used 51176K [0x07b30000, 0x0ad30000, 0x0ad30000)

object space 51200K, 99% used [0x07b30000,0x0ad2a0a0,0x0ad30000)

PSPermGen      total 12288K, used 2105K [0x03b30000, 0x04730000, 0x07b30000)

object space 12288K, 17% used [0x03b30000,0x03d3e4a8,0x04730000)

4、和serial Old收集器的差异

serial Old收集器是串行的进行垃圾回收,而Parallel old收集器是并行的进行垃圾回收。

[Full GC [PSYoungGen:3394K->3394K(6848K)] [ParOldGen: 51048K->51048K(51200K)]54442K->54442K(58048K) [PSPermGen: 2084K->2084K(12288K)], 0.0042710 secs][Times: user=0.00 sys=0.00, real=0.00 secs]

[GC [DefNew: 9108K->966K(9216K),0.0049332 secs][Tenured: 46824K->46893K(46920K), 0.0033687 secs] 47800K->47790K(56136K),[Perm : 2086K->2086K(12288K)], 0.0084489 secs] [Times: user=0.02 sys=0.00,real=0.01 secs]

ParOldGen表示是Parallel old在老年代进行回收;

Tenured表示是 serial old在老年代进行回收。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/fc51819434304a674abf7ee7aecd6b48.html