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在老年代進行回收。