Java Performance: The Definitive Guide cover

Java Performance: The Definitive Guide

Rating 4.0
Word count
487K words
Chapters
13
Series
Turing Programming Series
ISBN
9787115413765

Tags

Summary

This is the Chinese translation of the O'Reilly classic Java Performance: The Definitive Guide, written by Oracle architect Scott Oaks for the Java 7 and Java 8 platforms, systematically covering all aspects that affect Java application performance. The author treats performance tuning as a science and craft requiring accumulated knowledge, advocating that one first understand how the JVM and the Java platform work, then adjust parameters and code accordingly, rather than trying blindly by intuition. The book first discusses performance testing methods: why microbenchmarks easily distort results, how throughput, batch time, and response time should be measured separately, and how to handle variability in test results. It then introduces the performance toolbox, including OS-level CPU, disk, and network analysis tools, Java's built-in monitoring commands, and the trade-offs between sampling and profiling analyzers. In the JVM section, the book explains in detail the mechanisms of the just-in-time compiler and tiered compilation, compilation thresholds, and the use of flags such as inlining and escape analysis; it systematically sets out the principles of garbage collection algorithms, covering throughput collectors, CMS, and G1, and offers tuning approaches for parameters such as heap size, generation ratios, and metaspace. It also discusses heap and native memory usage analysis and leak hunting, object lifecycle management, and the performance impact of threads, thread pools, synchronization, and locks. Finally, the book extends to database access and Java SE API usage, explaining performance pitfalls in common code paths such as JDBC, connection pools, prepared statements, collection classes, and string processing, and summarizes commonly used tuning flags in an appendix for easy reference.

Editor's review

讲 Java 的书很多,真正把「性能」作为主题、并且讲得有体系的书却很少。这本书填补的正是这个空档:它不是一本速查手册,而是一条从测量到推理、从 JVM 内部到应用代码的完整逻辑链。 作者 Scott Oaks 长期在 Sun 和 Oracle 的 Java 性能团队工作,对 HotSpot 虚拟机的行为有第一手的经验。这种背景让本书有着难得的务实气质:它不承诺「设置某个参数就能提速几倍」,而是反复强调先量化、再归因、最后验证。关于微基准测试为何会骗人、吞吐量与响应时间为何常常此消彼长,这些论述能帮读者省下大量走弯路的调试时间。 对国内读者来说,G1 收集器、Java 飞行记录器、堆外内存排查这几部分尤其有价值,它们恰是线上问题排查中最常卡住的地方。书中的调优标志与参数说明可以当作案头参考,读完一遍之后仍值得反复翻阅。 需要说明的是,本书初版聚焦 Java 7 与 Java 8;如果项目已经迁移到 Java 11 及以上版本,建议同时参考 2022 年出版的第 2 版,那一版对 G1 和容器化环境做了更新。

Who it's for

A good fit for

  • 已经能熟练写 Java 代码、想系统弄懂 JVM 性能机制的开发者
  • 负责线上服务稳定性、需要排查 GC 与内存问题的后端工程师
  • 准备 Java 高级岗位面试、需要补足 JVM 调优知识体系的人
  • 使用 Java 做数据处理或批处理、关注吞吐量与延迟的技术人员

Not a good fit for

  • 完全没有 Java 基础、还在学习语法与面向对象的初学者
  • 希望找一本可以照抄参数配置的速查手册的人
  • 只想了解 Java 语言特性、对 JVM 原理不感兴趣的读者

Reading tips

  1. 先读第 2、3 章,掌握「先测量后优化」的思维方式与工具,再进入 JVM 内部机制。
  2. 把书中的调优标志在自己项目或本地压测环境里逐个验证,只记住结论效果有限。
  3. GC 与内存章节建议配合 GC 日志和堆转储实际练习,遇到线上问题时再回查对应章节。
  4. 若项目使用 Java 11 或更高版本,可对照第 2 版补充 G1 与容器化环境相关内容。

About the publisher

Posts & Telecom Press China · Founded in 1953

Posts & Telecom Press is known for its strengths in science and technology, computing, and information and communications titles, and has extended its publishing into photography, art, software learning, and inspirational growth, giving it a fairly diverse range. Its catalog includes computing and communications works such as Refactoring and Patterns (Revised Edition) and Huawei Switch Learning Guide (Second Edition), alongside bilingual collector's editions such as The Little Prince (Chinese-English-French illustrated collector's edition), The Great Gatsby, and Three Days to See. Beijing Ten Years: 1980-1990 and Ghost Blade: WLOP Personal Illustration Collection reflect its presence in photography and art. Its authors include Antoine de Saint-Exupéry, Helen Keller, Joshua Kerievsky, Wang Da, Zhang Zhaozeng, and WLOP.

Contents

  1. Chapter 1 Introduction
  2. Chapter 2 Performance Testing Methodology
  3. Chapter 3 The Java Performance Toolbox
  4. Chapter 4 Using the Just-In-Time Compiler
  5. Chapter 5 An Introduction to Garbage Collection
  6. Chapter 6 Garbage Collection Algorithms
  7. Chapter 7 Heap Memory Best Practices
  8. Chapter 8 Native Memory Best Practices
  9. Chapter 9 Threading and Synchronization Performance
  10. Chapter 10 Java Servers
  11. Chapter 11 Database Performance Best Practices
  12. Chapter 12 Java SE API Tips
  13. Appendix Tuning Flags Summary

FAQ

这本书适合零基础学 Java 的人读吗?
不太合适。本书假设读者已能编写 Java 程序并了解类、集合、线程等基本概念,重点在于解释 JVM 内部机制如何影响性能。初学者建议先通过入门教材打好语言基础,再回来读这本书会顺畅得多。
初版第 1 版和第 2 版有什么区别?
第 1 版由柳飞、陆明刚、臧秀涛翻译,2016 年出版,聚焦 Java 7 与 Java 8;第 2 版由党文亮翻译,2022 年出版,专注于更成熟的 Java 8 和 Java 11,更新了 G1 垃圾回收器、Java 飞行记录器以及 Java 在容器化环境下的性能变化等内容。
书里的调优参数现在还能直接用在生产环境吗?
书中讲解的多数概念和标志思路仍然有效,但部分参数默认值随 JDK 版本变化较大。建议对照自己使用的 JDK 版本查阅官方文档确认默认值与推荐写法,并在测试环境中验证后再应用到生产。
读这本书需要先了解垃圾回收吗?
不需要预先掌握。第 5 章从分代回收的基本概念讲起,逐步过渡到吞吐量回收器、CMS 和 G1 的算法与调优。但如果事先了解一点堆结构和新老年代的概念,阅读会更轻松。
这本书主要解决哪些实际问题?
典型场景包括 GC 停顿过长、堆内存持续增长甚至内存溢出、CPU 使用率异常偏高、线程阻塞与锁竞争、数据库访问成为瓶颈,以及集合与字符串等 Java SE API 使用不当带来的隐性开销。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

About the author

Scott Oaks Author

Scott Oaks is a technical author about whom limited public information is currently available in Chinese; neither his dates of birth and death nor his nationality are clearly recorded. Two of his works are included in the collection, both centered on Java performance, with Java Performance: The Definitive Guide as the representative title. Judging by the common categories, these books fall under computing, software learning, and programming design, and are aimed at developers who want to understand the runtime efficiency of Java programs more deeply. His writing focuses on the practical field of performance tuning, explaining problems and methods rather than offering broad conceptual surveys. Based on the available material, his recognition among Chinese readers comes mainly from this performance guide, which is a useful reference for engineers concerned with Java performance; his personal background and full body of work still await further public information.