Java Concurrency in Practice cover

Java Concurrency in Practice

Rating 4.5
Chapters
1
Series
HZ Professional Developer Series
ISBN
9787111370048

Tags

Summary

Java Concurrency in Practice is a recognized classic in the field of Java concurrency. Its authors come from the expert group in the Java Community Process responsible for concurrency utilities (JSR 166), and a considerable number of the APIs in the java.util.concurrent package came from their hands. The book is not content to list APIs; it focuses on explaining why these concurrency utilities exist, how to use them correctly, and the design principles, patterns, and mental models behind them. The book is divided into four parts and 16 chapters in total. Part I, "Fundamentals," begins with the concepts of concurrency and thread safety, and discusses atomicity, race conditions, intrinsic locks and reentrancy, object visibility and safe publication, thread confinement and immutability, and how to compose small thread-safe classes into larger thread-safe components. Part II, "Structuring Concurrent Applications," centers on task execution, introducing the Executor framework, task cancellation and shutdown, configuration and extension of thread pools, and uses single-threaded subsystems such as graphical user interfaces to illustrate the relationship between concurrency and responsiveness. Part III, "Liveness, Performance, and Testing," analyzes liveness hazards such as deadlock, explains Amdahl's law, lock contention, and context-switching overhead, and presents methods for correctness testing and performance testing of concurrent programs. Part IV, "Advanced Topics," goes deep into explicit locks, AQS and custom synchronizers, atomic variables and non-blocking algorithms, and finally arrives at the theoretical foundation of the Java Memory Model. The book is interspersed with numerous examples and "dangerous" code snippets drawn from real engineering, helping readers build an intuition for judging the correctness of concurrent code. The book was nominated for the 16th Jolt Award and is an advanced reading that Java backend, middleware, and framework developers cannot avoid. Readers should have some foundation in Java syntax and object-oriented programming before reading.

Editor's review

市面上的 Java 并发书大致分两类:一类讲 API 怎么调,一类讲原理讲到让人望而生畏。这本书罕见地两头都占:它的作者就是 java.util.concurrent 的设计者,讲的不是二手转述,而是一手设计意图。 最值得称道的是它的“工程感”。书中给出的不是孤立的语法点,而是判断标准:这段代码安全吗?这个锁会不会带来性能陷阱?这个线程池大小是否合理?为什么这个看似同步的类仍然会失效?作者用大量“正确 vs 错误”的对照代码,把抽象的 happens-before 规则落成可以照着检查的清单。 当然,这本书成书于 Java 5/6 时代,书中关于 GUI 单线程模型、部分性能对比的内容已经有些年代感,Java 8 之后出现的 CompletableFuture、并行流、虚拟线程等新特性也不在覆盖范围内。但正因如此,它更像是在打地基:把内存模型、可见性、锁的语义这些不变的底层概念讲透,后面学任何新框架都事半功倍。这也是它十几年长销、豆瓣评分稳定在 9 分以上的原因。

Who it's for

A good fit for

  • 有 Java 基础、希望系统攻克并发与多线程的中高级开发者
  • 需要维护或排查线上并发问题的后端、中间件工程师
  • 准备阅读 JUC 源码、想理解其设计意图的框架学习者
  • 计算机专业高年级学生与研究生作为并发课程配套读物

Not a good fit for

  • 完全没有 Java 语法基础、尚未写过类的初学者
  • 只想速查 API 用法、需要即查即用手册的读者
  • 希望学习 Java 8 之后 CompletableFuture、虚拟线程等新特性的读者

Reading tips

  1. 第一遍通读第1—5章打牢线程安全与对象共享的基础,不要跳读第3章可见性。
  2. 第6—9章建议边读边用 Executor 框架重写自己项目里的线程创建代码,形成肌肉记忆。
  3. 第13—16章较硬,可配合 OpenJDK 中 JUC 源码与《Java 语言规范》第17章对照阅读。
  4. 读完后做一份“并发缺陷自查清单”,把书中的规则整理成团队代码评审条目。

About the publisher

China Machine Press China · Founded in 1950

In addition to science and technology and professional publishing, the books in our catalog from China Machine Press also reflect a sustained focus on psychology, computing, management, finance and economics, and social sciences. In psychology, the catalog includes works by C. G. Jung and introductions to analytical psychology, as well as applied topics such as stress and health, and addiction and healing. In computing, it features Structure and Interpretation of Computer Programs (JavaScript Edition). Management and finance titles include Administrative Behavior (4th Edition), The Price of Inequality (Collector's Edition), and This Time Is Different: Eight Centuries of Financial Folly (Commemorative Edition). In the philosophy and history of science, there is The Worldview: The Third Edition. Relevant authors include C. G. Jung, William McGuire, Sonu Shamdasani, and Gabor Maté. Public information is limited; the above summarizes the publisher's profile based solely on the books in our catalog.

Contents

  1. Professional Developer Series

FAQ

这本书适合零基础或刚学 Java 的人读吗?
不太适合。书中默认读者熟悉 Java 语法、异常、集合框架与基本的面向对象设计,开篇就直接讨论原子性和竞态条件。初学者建议先掌握 Java 基础并写过一两个多线程小程序,再读此书会顺畅很多。
2012 年的版本现在读会不会过时?
核心内容不过时。线程安全、可见性、锁语义、Java 内存模型、AQS 等底层机制至今未变,JUC 的设计思路也仍是现代并发的基础。但书中未覆盖 Java 8 的 CompletableFuture、并行流以及后续的虚拟线程,这部分需要另找资料补充。
它和《Java并发编程实践》(电子工业出版社2007年版)是同一本书吗?
是同一本英文原书 Java Concurrency in Practice 的不同中文译本。电子工业出版社2007年版由韩锴、方秒翻译,书名为《JAVA并发编程实践》;机械工业出版社2012年版由童云兰翻译,书名为《Java并发编程实战》,即通常所说的“Java 并发编程实战”。
这本书对面试或实际工作帮助大吗?
帮助很大。面试中常考的 happens-before、volatile 与 synchronized 区别、线程池参数与拒绝策略、AQS 原理、死锁排查等,书中都有系统讲解;工作中排查线程安全缺陷、合理配置线程池也能直接套用书里的判断方法。
读完需要多长时间?
全书 16 章约 300 页,按每周读 2—3 章、并动手敲示例的节奏,一般 6—8 周可以读完一遍。第13—16章建议放慢速度,配合源码阅读,二刷时再重点攻克。

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.

More by the same author

Top rated in the same category