Java Concurrency: Inside the JDK Source Code cover

Java Concurrency: Inside the JDK Source Code

No rating yet
Word count
307 words
Chapters
8
ISBN
9787121379727

Tags

Summary

This book examines the internal workings of Java concurrency, using the java.util.concurrent package in the JDK as its main thread and dissecting the implementation mechanisms behind commonly used concurrency components layer by layer. The book has eight chapters. Chapter 1 starts with multithreading fundamentals, sorting out easily confused topics such as thread shutdown, interruption, synchronized, wait/notify, volatile, the Java Memory Model and happens-before, memory barriers, and final semantics, and closes with lock-free queues, stacks, and linked lists as comprehensive case studies. Chapter 2 covers the Atomic classes, from CAS and Unsafe to underlying spinning and blocking, the ABA problem, field updaters and array atomics, and Striped64 and LongAdder's segmented accumulation and false sharing. Chapter 3 dissects Lock and Condition, explaining mutex reentrancy, fair and nonfair implementations, AQS blocking queues and wakeup mechanisms, read-write locks, Condition, and StampedLock. Chapter 4 covers synchronization utilities such as Semaphore, CountDownLatch, CyclicBarrier, Exchanger, and Phaser. Chapters 5 through 8 cover concurrent containers including blocking queues, BlockingDeque, CopyOnWrite, ConcurrentLinkedQueue, ConcurrentHashMap, and ConcurrentSkipListMap; thread pools and Future; the work-stealing principle of ForkJoinPool; and the asynchronous orchestration and internal computation graph of CompletableFuture. The book proceeds from shallow to deep, layer by layer, aiming to give readers an intuitive yet deep understanding of multithreaded programming rather than leaving them at the level of concepts.

Editor's review

市面上的并发书大致分两类:一类讲 API 用法与最佳实践,一类讲理论模型。本书选择了第三条路——直接读源码。作者余春龙从线程的中断与优雅关闭讲起,把 happen-before、内存屏障、CAS 这些平时容易被“背下来”的概念,放回真实代码语境里解释,读者能看到规则是怎么被落实的。第 3 章围绕 AQS 展开的锁与 Condition 剖析是全书的重心,公平与非公平的差别、阻塞队列的入队出队、unlock 的唤醒传播,都配有清晰的源码拆解,对理解 ReentrantLock、ReentrantReadWriteLock、Semaphore 等一整套组件极有帮助。后半部分对 ConcurrentHashMap 在 JDK 7 与 JDK 8 中的两种实现、ThreadPoolExecutor 的任务提交与执行流程、ForkJoinPool 的工作窃取队列与 ctl 状态控制,都讲得比较扎实;最后一章把 CompletableFuture 的任务原型、链式执行与 allOf 的计算图讲透,是不少同类书较少涉及的内容。全书约 250 页、30 余万字,篇幅克制,适合作为床头或工位旁的“随查随读”型参考。需要注意的是,书中源码分析基于 JDK 8 时代的实现,阅读时最好对照源码,并结合当前 JDK 版本的变化做取舍。

Who it's for

A good fit for

  • 有 1~3 年 Java 开发经验、想弄清 JUC 底层原理的工程师
  • 准备 Java 后端面试、需要系统梳理 AQS、线程池、CAS 等考点的求职者
  • 做高并发服务、需要判断并发组件选型与性能取舍的开发者
  • 读过《Java并发编程实战》但希望进一步看源码实现细节的读者

Not a good fit for

  • 完全没有 Java 语法基础、尚未接触过多线程的初学者
  • 只想找现成 API 用法和代码模板、不打算读源码的读者
  • 对操作系统与 JVM 内存模型完全无概念、希望零基础入门的读者

Reading tips

  1. 按章节顺序读:第 1 章的内存模型与内存屏障是后面所有内容的地基,尽量不要跳过。
  2. 边读边开 IDE 对照 JDK 源码,把书中的方法调用链在源码里走一遍,效果远胜于纯阅读。
  3. 读完后自己动手实现一个简化版 AQS 或线程池,用验证代替记忆,才能真正内化。
  4. 注意书中源码基于较早的 JDK 版本,遇到与当前 JDK 实现不一致处,以官方源码和文档为准。

About the publisher

Publishing House of Electronics Industry China · Founded in 1982

The Publishing House of Electronics Industry is a comprehensive publisher distinguished by its focus on electronic information and related fields. Judging from the more than 3,000 titles in its catalogue, its publishing covers programming and design, artificial intelligence, computer science, finance and economics, photography, and social sciences, attending both to cutting-edge technology and to general readers. Representative titles include Factor Investing: Methods and Practice, x86 Assembly Language: From Real Mode to Protected Mode, The RISC-V Reader, Artificial Intelligence: Speech Recognition, Understanding and Practice, Phased Array Radar Technology, Radar Target Characteristics, and 100 Go Mistakes and How to Avoid Them, most of which centre on technical methods and engineering practice. Its authors include Shi Chuan, Li Zhong, Wang Xiaobo, David Patterson, Andrew Waterman, and Yu Zihao, among others from China and abroad. Owing to limited public information, no further publishing features are elaborated here.

Contents

  1. Chapter 1: Multithreading Basics
  2. Chapter 2: Atomic Classes
  3. Chapter 3: Lock and Condition
  4. Chapter 4: Synchronization Utilities
  5. Chapter 5: Concurrent Containers
  6. Chapter 6: Thread Pools and Future
  7. Chapter 7: ForkJoinPool
  8. Chapter 8: CompletableFuture

FAQ

这本书需要什么基础才能读?
至少应熟悉 Java 基本语法、多线程的基本用法(Thread、synchronized、线程池 API),并了解 JVM 内存区域的粗浅概念。书中直接进入源码分析,基础薄弱时容易被方法调用链绕晕,建议先读一本并发入门书再回来。
书中的源码分析基于哪个 JDK 版本?
主要基于 JDK 8 时代的 Concurrent 包实现,例如 ConcurrentHashMap 同时对比了 JDK 7 的分段锁与 JDK 8 的 CAS + synchronized 方案。若你使用更高版本 JDK,个别实现细节可能已有调整,建议对照官方源码阅读。
这本书和《Java并发编程实战》有什么区别?
《Java并发编程实战》偏重并发设计原则、线程安全策略与最佳实践,是“怎么用好”;本书偏重 JDK 内部源码,回答“为什么这样实现、底层靠什么保证”。两者互补,先读前者建立设计观念,再读本书深入实现细节,效果更好。
这本书适合用来准备面试吗?
适合作为面试前的原理梳理材料,AQS、CAS、线程池参数与执行流程、ConcurrentHashMap 演进、ForkJoinPool 工作窃取等都是高频考点。但书中不侧重题目与答题技巧,仍需要自己总结并结合实际项目经验。
全书大概多少篇幅,需要读多久?
正文约 250 页、30 余万字,分为 8 章。按每天一章、边读边对照源码的节奏,大约两到三周可以完成第一遍;源码类书籍建议至少读两遍,第二遍可只精读第 3 章锁与第 6 章线程池。

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.

Top rated in the same category