The Art of Java Concurrency Programming cover

The Art of Java Concurrency Programming

Rating 3.6
Chapters
40
Series
An advanced concurrency programming guide for developers with some Java background, co-written by three technical experts—Fang Tengfei, Wei Peng, and Cheng Xiaoming—who have long worked on frontline e-commerce and internet systems. The content draws on their technical articles and practice summaries published on concurrency programming sites, InfoQ, Programmer, and other communities and media. The book opens with "where concurrency is actually hard," covering the three core challenges of context switching, deadlock, and resource limits, then dissects the underlying implementation of volatile, synchronized, and atomic operations at both the CPU and JVM levels. It then devotes substantial space to the Java Memory Model: reordering and sequential consistency, happens-before rules, the memory semantics of volatile and locks, final field semantics, and correct patterns for double-checked locking and lazy initialization. At the fundamentals and tools level, it covers thread lifecycle, start and termination, interruption, the classic wait/notify paradigm, ThreadLocal, and other inter-thread communication mechanisms; it then unpacks the Java concurrency package layer by layer: the Lock interface and AQS, reentrant and read-write locks, Condition, concurrent containers such as ConcurrentHashMap and ConcurrentLinkedQueue, the Fork/Join framework, atomic classes, concurrency utilities such as CountDownLatch, CyclicBarrier, Semaphore, and Exchanger, and the implementation and configuration advice for thread pools and the Executor framework. It closes with practice content including the producer-consumer pattern, online problem diagnosis, performance testing, and asynchronous task pools. Concise and focused on principles and source-code analysis, with abundant example code, the book suits Java developers moving from "using concurrency APIs" to "understanding why concurrency is designed this way."
ISBN
9787111508243

Tags

Summary

This book is an advanced guide to concurrent programming for developers with some Java background. It is co-authored by Fang Tengfei, Wei Peng, and Cheng Xiaoming, three technical experts with long-term frontline experience in e-commerce and internet system development, and its content is drawn from technical articles and practical summaries they published on communities and media outlets such as Concurrent Programming Network, InfoQ, and Programmer.

The book begins by asking "what exactly makes concurrency so hard," first discussing the three core challenges of concurrent programming: context switching, deadlock, and resource limits. It then analyzes the underlying implementation principles of volatile, synchronized, and atomic operations from both the CPU and JVM levels. After that, it devotes considerable space to a systematic explanation of the Java Memory Model: reordering and sequential consistency, the happens-before rules, the memory semantics of volatile and locks, the semantics of final fields, and the correct implementation of double-checked locking and lazy initialization.

At the foundational and tooling levels, the book explains the thread lifecycle, starting and terminating threads, the interruption mechanism, the classic wait/notify paradigm, ThreadLocal, and other means of inter-thread communication. It then breaks down the Java concurrency package layer by layer: the Lock interface and the AQS queue synchronizer, reentrant locks and read-write locks, Condition, concurrent containers such as ConcurrentHashMap and ConcurrentLinkedQueue, the Fork/Join framework, atomic operation classes, concurrency utilities such as CountDownLatch, CyclicBarrier, Semaphore, and Exchanger, and the implementation principles and configuration recommendations of thread pools and the Executor framework. It concludes with practical content including the producer-consumer pattern, online problem diagnosis, performance testing, and asynchronous task pools.

Concise in length and focused on principles and source code analysis, the book includes abundant example code and is suitable for systematic study by Java developers who wish to move from "knowing how to use concurrency APIs" to "understanding why concurrency is designed the way it is."

Editor's review

在中文 Java 技术书里,讲并发的不算少,但能把“为什么要这样设计”讲清楚的并不多。这本书最大的价值在于它的纵深:从 CPU 缓存、内存屏障、对象头与锁升级,一路打通到 JMM 的 happens-before 规则,再到 AQS、并发容器与线程池的源码实现,形成一条从硬件到框架的完整链条。 全书只有两百多页,却覆盖了并发编程几乎全部核心考点,作者没有堆砌 API 手册式的条目,而是围绕“问题—原理—实现—示例”展开,读起来更像一次系统性的源码导读。对准备技术面试的开发者,书中对 volatile 内存语义、双重检查锁定、锁膨胀、ConcurrentHashMap 分段设计的讲解,都是高频且容易被追问的内容。 需要提醒的是,本书由三位作者合著,章节之间风格略有差异,部分细节也存在勘误与过时之处,个别示例的写法在今天的 JDK 中已有更简洁的替代方案。读者最好把它当作“原理路线图”,配合官方文档、JDK 源码和《Java并发编程实战》一起读。若追求更新的内容,可考虑 2023 年出版的修订第 2 版。

Who it's for

A good fit for

  • 有 1–3 年 Java 开发经验、想系统理解并发原理的后端工程师。
  • 准备中高级 Java 岗位面试,需要梳理 JMM、AQS、线程池等考点的求职者。
  • 习惯通过阅读 JDK 源码提升设计能力的技术人员。
  • 计算机专业高年级学生或研究生,把并发编程作为课程延伸阅读。

Not a good fit for

  • 完全没有 Java 基础、尚未掌握集合与泛型语法的初学者。
  • 只想查阅 API 用法速查表的读者,本书更偏原理而非手册。
  • 希望深入分布式一致性、消息中间件等系统级并发问题的读者。

Reading tips

  1. 按章节顺序通读,第 3 章内存模型建议反复读,先建立 happens-before 直觉再读后续并发包源码。
  2. 边读边打开 JDK 源码对照,重点跟踪 AQS 的独占/共享获取流程与线程池的 worker 执行路径。
  3. 动手复现书中的上下文切换、死锁与双重检查锁定示例,用 jstack、JFR 等工具观察实际行为。
  4. 关注版本差异:书中基于较早期 JDK,建议结合当前 JDK 文档确认 ConcurrentHashMap、FutureTask 等实现的演变。

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. Preface
  2. Chapter 1 The Challenges of Concurrency Programming
  3. 1.1 Context Switching
  4. 1.1.1 Is Multithreading Always Faster?
  5. 1.1.2 Measuring the Number and Duration of Context Switches
  6. 1.1.3 How to Reduce Context Switching
  7. 1.1.4 Reducing Context Switching in Practice
  8. 1.2 Deadlock
  9. 1.3 The Challenge of Resource Limits
  10. 1.4 Chapter Summary
  11. Chapter 2 The Underlying Implementation Principles of Java's Concurrency Mechanisms
  12. 2.1 Applications of volatile
  13. 2.2 Implementation Principles and Applications of synchronized
  14. 2.2.1 Java Object Headers
  15. 2.2.2 Lock Escalation and Comparison
  16. 2.3 Implementation Principles of Atomic Operations
  17. 2.4 Chapter Summary
  18. Chapter 3 The Java Memory Model
  19. 3.1 Fundamentals of the Java Memory Model
  20. 3.1.1 Two Key Questions of Concurrency Programming Models
  21. 3.1.2 The Abstract Structure of the Java Memory Model
  22. 3.1.3 Reordering from Source Code to Instruction Sequence
  23. 3.1.4 Classification of Concurrency Programming Models
  24. 3.1.5 Introduction to happens-before
  25. 3.2 Reordering
  26. 3.2.1 Data Dependence
  27. 3.2.2 as-if-serial Semantics
  28. 3.2.3 Program Order Rule
  29. 3.2.4 The Impact of Reordering on Multithreading
  30. 3.3 Sequential Consistency
  31. 3.3.1 Data Races and Sequential Consistency
  32. 3.3.2 The Sequentially Consistent Memory Model
  33. 3.3.3 The Sequential Consistency Effect of Synchronized Programs
  34. 3.3.4 Execution Characteristics of Unsynchronized Programs
  35. 3.4 The Memory Semantics of volatile
  36. 3.4.1 Characteristics of volatile
  37. 3.4.2 The happens-before Relationship Established by volatile Write-Read
  38. 3.4.3 The Memory Semantics of volatile Write-Read
  39. 3.4.4 Implementation of volatile Memory Semantics
  40. 3.4.5 Why JSR-133 Strengthened the Memory Semantics of volatile

FAQ

这本书适合零基础学 Java 的人读吗?
不太适合。本书默认读者熟悉 Java 语法、集合与基本多线程概念,开篇即进入上下文切换和内存模型,零基础读者容易卡在第 2、3 章,建议先补 Java 基础与《Java编程思想》一类的入门书。
这本书和《Java并发编程实战》有什么区别?
《Java并发编程实战》偏重并发设计原则与最佳实践,作者团队来自 JSR-166 专家组;本书更聚焦 Java 底层实现机制、JMM 与 JDK 源码剖析,篇幅更短、更贴近中文读者的面试与源码阅读需求,两者互补。
书中的内容和现在的 JDK 版本还匹配吗?
本书 2015 年出版,基于 JDK 7/8 前后,核心概念如 JMM、happens-before、AQS、线程池原理依然成立;但 ConcurrentHashMap 的分段锁设计、FutureTask 等具体实现已随版本演进而变化,建议对照当前 JDK 源码阅读。
三个作者合著会不会内容割裂?
各章相对独立,风格确有差异,部分读者反馈第 3 章最成体系、后几章略显提纲化,个别示例存在勘误。可以按主题挑读,遇到与主流资料不一致处,以官方文档和源码为准。
有必要买第 2 版吗?
第 2 版于 2023 年由机械工业出版社出版,修订与新增内容超过 50%,并补充了分布式编程与分布式锁等章节。若关心最新实践,第 2 版更合适;只想理解经典并发原理,第 1 版依然够用。

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

魏鹏 Author

Information about Wei Peng currently available to the public is limited, and details such as his nationality, dates of birth and death, and educational background cannot be confirmed. Judging from the works held in the collection, he participated in writing two biographical books, Liu Hulan and Huang Jiguang, both of which focus on heroic figures in Chinese revolutionary history. Works of this kind typically recount a person's life and deeds in an accessible, documentary style, emphasizing the clear presentation of historical facts and the expression of spiritual meaning. They are aimed at general readers, especially young people, and serve the functions of historical education and the transmission of values. Both books are classified under general biography, indicating that his writing leans toward popular works of documented lives. Overall, Wei Peng's work centers on biographies of heroic figures, with a plain style and clear narrative, and carries certain significance for spreading stories of figures from revolutionary history. Because verifiable material is quite limited, any assessment of his writing career and overall achievements awaits further information.

程晓明 Author

Cheng Xiaoming is an author about whom little public information is available. The only work currently on record is A Pharmacoeconomic Evaluation Study of Tongmai Yangxin Pills, commonly classified under finance and economics. The title indicates that the author's writing focuses on pharmacoeconomic evaluation, offering an economic analysis of a specific traditional Chinese medicine product and touching on intersecting issues such as medical costs, therapeutic efficacy, and resource utilization. Such subject matter requires knowledge of both medicine and economics, and the writing tends toward data-supported, empirical analysis in a rigorous and pragmatic style. Because only this one work is held in the collection, nothing can be confirmed about the author's nationality, dates of birth and death, educational background, or professional positions, and no speculation is offered. On the available evidence, Cheng Xiaoming writes in the specialized field of pharmacoeconomic evaluation, addressing practitioners and researchers in public health, health economics, and policy studies, and the work offers a useful analytical framework for economic assessment of the product concerned.

More by the same author

Top rated in the same category