Skip to Content
Java性能权威指南(第2版)
book

Java性能权威指南(第2版)

by Scott Oaks
April 2022
Intermediate to advanced
348 pages
11h 21m
Chinese
Posts & Telecom Press
Content preview from Java性能权威指南(第2版)
垃圾回收算法
|
141
针对并发模式失败的优化
优化
CMS
的首要目的是确保不会发生并发模式失败或晋升失败。正如
CMS
的
GC
日志
显示的那样,并发模式失败是因为
CMS
清理老年代的速度不够快
。当执行新生代回收时,
CMS
计算出没有足够的空间容纳这些将晋升到老年代的对象,所以会先回收老年代。
刚开始填充老年代时,对象是一个挨一个放置的。当老年代被填充到一定程度时(默认为
70%
)
,并发周期就会开始,后台
CMS
线程会开始在老年代中扫描垃圾。在这个时候,竞
争也就开始了。
CMS
必
须在老年代的剩余部分(
30%
)被填满之前,完成对老年代的扫描
并释放对象。如果并发周期在竞争中失利,
CMS
就会经历并发模式失败。
我们可以通过多种方式来避免这种失败:
•
让老年代空间更大一些,要么调整新生代和老年代的比例,要么增加更多的堆空间;
•
更频繁地运行后台线程;
•
使用更多的后台线程。
自适应大小和
CMS
回收器
CMS
回收器使用两个标志
MaxGCPauseMllis=
N
和
GCTimeRatio=
N
来决定应该使用多大的
堆和代。
CMS
所采取的方法与其他回收器的一个显著不同之处,就是除非发生
Full GC
,否则
永远不会调整新生代的大小。由于
CMS
的目标是永远不发生
Full GC
,这意味着精心
调校过
CMS
的应用程序永远不应该调整新生代的大小。
由于
CMS
会自适应地调整堆和元空间的大小,因此在程序启动阶段,并发模式失败
可能会频繁发生。启动
CMS
时采用较大的初始堆(和较大的元空间)是个好主意,
这时增大堆是为了防止失败,这是一个特殊情况。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Java数据科学实战

Java数据科学实战

Michael R. Brzustowicz, PhD
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton

Publisher Resources

ISBN: 9787115587367