新生代收集器
Serial收集器
采用
复制算法
,单线程收集器,它进行垃圾收集时,必须暂停其他所有工作线程,直到它收集结束,jdk1.3.1之前新生代收集器唯一选择
ParNew收集器
采用
复制算法
,Serial收集器的多线程版本
Parallel Scavenge收集器
采用
复制算法
,并行多线程收集器。它的目标则是达到一个可控制的吞吐量。吞吐量=运行用户代码时间/(运行用户代码时间+垃圾收集时间),虚拟机运行100分钟,垃圾收集花掉1分钟,着吞吐量就是99%。
老年代收集器
Serial Old收集器
采用
标记-整理算法
,单线程收集器
Parallel Old收集器
采用
标记-整理算法
,多线程收集器
CMS收集器
以获取最短回收停顿时间为目标的收集器,采用
标记-清除算法
,它的优点就是:并发标记,低停顿。
老年代新生代并存收集器
G1收集器
HotSpot团队赋予它的使命是未来替换掉JDK1.5发布的CMS收集器。与其他收集器相比,它具备如下特点:并行与并发、分代收集、空间整合、可预测的停顿
总结
- For server-class machine, defined as a machine with 2 or more physical processors and 2 or more GB of physical memory (regardless of the platform), the default garbage collector is the parallel collector (also known as throughput collector).
- For client-class machine, defined as a 32-bit platform on Windows or a single-processor machine, the default garbage collector is the serial collector.
Since practically all machines have 2 or more CPU, a machine is practically always considered server-class by the JVM. That’s why you will find a lot of references considering the parallel collector to be the default garbage collector.
- 当有多核cpu时,采用Parallel (old)收集器。Jdk1.5中提供了CMS收集器,但他无法与Parallel Scavenge配合使用,新生代只能选择Serial或者ParNew。
- CMS收集器停顿时间短,适合在与用户交互的程序,Parallel适合于在后台运行不需要太多交互的任务,它追求高吞吐量。
- 默认垃圾收集器
- Java 7 - Parallel (old) GC
- Java 8 - Parallel (old) GC
- Java 9 - G1 GC
并行与并发
- 并行(Parallel):指多条垃圾收集线程并行工作,但此时用户线程处于等待状态。
- 并发:指用户线程和垃圾收集线程同时执行(但不一定是并行的,可能会交替执行),用户线程在继续执行,而垃圾收集程序运行在另外一个cpu上。
参考: 深入理解java虚拟机