Java Concurrency in Practice cover

Java Concurrency in Practice

Rating 4.4
Chapters
25
ISBN
9787121043161

Tags

Summary

This book is the Chinese translation of the classic work in the field of Java concurrency, Java Concurrency in Practice, jointly written by leading members of the JSR 166 expert group (the creators of the java.util.concurrent concurrency toolkit): Brian Goetz, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, and Doug Lea. Set against the new concurrency features introduced in Java SE 5 and 6, the book begins with the basic concepts of concurrency and thread safety, then explains atomicity, locking mechanisms, object sharing and safe publication, the design and composition of thread-safe classes, synchronized and concurrent containers, blocking queues and the producer–consumer pattern, synchronizers, and structured concurrent application techniques such as the Executor framework, task cancellation and shutdown, and thread pool configuration. On this foundation, the book further discusses identifying and avoiding liveness hazards such as deadlock, measuring and optimizing performance and scalability (including Amdahl's law, reducing lock contention, and context-switching overhead), testing concurrent programs for correctness and performance, and goes in depth into explicit locks and ReentrantLock, read-write locks, condition queues, AbstractQueuedSynchronizer, atomic variables, and non-blocking algorithms, closing with the Java Memory Model and safe publication. What the book stresses is not merely how to use the APIs but why they are designed as they are, building for readers reusable design principles, patterns, and mental models for concurrent programs.

Editor's review

《Java并发编程实践》并非一本罗列 API 的手册,它回答的是“为什么会出错”与“怎样才能不出错”。六位作者均为 JSR 166 专家组核心成员,java.util.concurrent 里的那些类就是他们亲手设计并写入规范的,因此书中关于同步容器与并发容器、Executor、线程池、AQS 的讲述带着设计者视角的“内部消息”,这是绝大多数教程难以替代的。 全书结构清晰:基础(线程安全、对象共享与组合、构建块)→ 结构化并发应用(任务执行、取消与关闭、线程池、GUI)→ 活跃性、性能与测试 → 高级主题(显式锁、自定义同步工具、原子变量与非阻塞、Java 内存模型)。它把可见性、原子性、有序性这些原本模糊的概念落到代码与内存模型的因果链上,配合贯穿全书的实例与“危险模式”警示,读者可以边读边对照自己的项目。 需要提醒的是,2007 年电子工业版译文质量存在争议,术语与行文偶有生硬之处;若追求更顺畅的阅读体验,可参考机械工业出版社 2012 年童云兰译本《Java并发编程实战》。

Who it's for

A good fit for

  • 有 Java 基础、写过简单多线程代码,希望系统补齐并发知识体系的开发者
  • 正在处理线上并发缺陷(数据错乱、偶发死锁、切换开销大)的后端工程师
  • 需要设计线程安全类与基础组件、想理解 JDK 并发包设计取舍的架构师
  • 讲授 Java 并发课程、需要权威参考框架的高校教师与培训讲师

Not a good fit for

  • 完全没写过 Java、连语法与集合框架都不熟悉的零基础读者
  • 只想复制粘贴代码、不愿意思考内存模型与设计原则的读者
  • 主要使用 Go、Rust、C++ 等其他语言并寻求对应并发方案的读者

Reading tips

  1. 先通读第 2—5 章第一部分,把原子性、可见性、安全发布三个概念吃透,这是全书地基。
  2. 第二部分建议对照 JDK 源码与自己的项目阅读,读完每章就把 Executor、线程池配置用到实际代码里。
  3. 第 13—16 章属高级主题,可在遇到自定义同步器或排查内存可见性问题时再精读,不必强求一次读完。
  4. 书中示例代码可下载后亲手运行并故意制造竞态,再对照书中的修复方式,效果远好于只看不练。

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. Code List
  2. Foreword
  3. Chapter 1 Introduction (1.1 A Brief History of Concurrency; 1.2 Benefits of Threads; 1.3 Risks of Threads; 1.4 Threads Are Everywhere)
  4. Part 1 Fundamentals
  5. Chapter 2 Thread Safety (2.1 What Is Thread Safety?; 2.2 Atomicity; 2.3 Locking; 2.4 Guarding State with Locks; 2.5 Liveness and Performance)
  6. Chapter 3 Sharing Objects (3.1 Visibility; 3.2 Publication and Escape; 3.3 Thread Confinement; 3.4 Immutability; 3.5 Safe Publication)
  7. Chapter 4 Composing Objects (4.1 Designing a Thread-Safe Class; 4.2 Instance Confinement; 4.3 Delegating Thread Safety; 4.4 Adding Functionality to Existing Thread-Safe Classes; 4.5 Documenting Synchronization Policies)
  8. Chapter 5 Building Blocks (5.1 Synchronized Collections; 5.2 Concurrent Collections; 5.3 Blocking Queues and the Producer–Consumer Pattern; 5.4 Blocking and Interruptible Methods; 5.5 Synchronizers; 5.6 Building an Efficient, Scalable Result Cache)
  9. Part 2 Structuring Concurrent Applications
  10. Chapter 6 Task Execution (6.1 Executing Tasks in Threads; 6.2 The Executor Framework; 6.3 Finding Exploitable Parallelism)
  11. Chapter 7 Cancellation and Shutdown (7.1 Task Cancellation; 7.2 Stopping a Thread-Based Service; 7.3 Handling Abnormal Thread Termination; 7.4 JVM Shutdown)
  12. Chapter 8 Applying Thread Pools (8.1 Implicit Couplings Between Tasks and Execution Policies; 8.2 Sizing Thread Pools; 8.3 Configuring ThreadPoolExecutor; 8.4 Extending ThreadPoolExecutor; 8.5 Parallelizing Recursive Algorithms)
  13. Chapter 9 GUI Applications (9.1 Why Are GUIs Single-Threaded?; 9.2 Short-Lived GUI Tasks; 9.3 Long-Lived GUI Tasks; 9.4 Shared Data Models; 9.5 Other Forms of Single-Threaded Subsystems)
  14. Part 3 Liveness, Performance, and Testing
  15. Chapter 10 Avoiding Liveness Hazards (10.1 Deadlock; 10.2 Avoiding and Diagnosing Deadlocks; 10.3 Other Liveness Hazards)
  16. Chapter 11 Performance and Scalability (11.1 Thinking About Performance; 11.2 Amdahl's Law; 11.3 Costs Introduced by Threads; 11.4 Reducing Lock Contention; 11.5 Example: Comparing Map Performance; 11.6 Reducing Context-Switch Overhead)
  17. Chapter 12 Testing Concurrent Programs (12.1 Testing for Correctness; 12.2 Testing for Performance; 12.3 Avoiding Performance Testing Pitfalls; 12.4 Supplemental Test Methods)
  18. Part 4 Advanced Topics
  19. Chapter 13 Explicit Locks (13.1 Lock and ReentrantLock; 13.2 Performance Considerations; 13.3 Fairness; 13.4 Choosing Between synchronized and ReentrantLock; 13.5 Read-Write Locks)
  20. Chapter 14 Building Custom Synchronizers (14.1 Managing State Dependence; 14.2 Using Condition Queues; 14.3 Explicit Condition Objects; 14.4 Anatomy of a Synchronizer; 14.5 AbstractQueuedSynchronizer; 14.6 AQS in java.util.concurrent)
  21. Chapter 15 Atomic Variables and Nonblocking Synchronization (15.1 Disadvantages of Locking; 15.2 Hardware Support for Concurrency; 15.3 Atomic Variable Classes; 15.4 Nonblocking Algorithms)
  22. Chapter 16 The Java Memory Model (16.1 What Is a Memory Model, and Why Do We Need It?; 16.2 Publication; 16.3 Initialization Safety)
  23. Appendix A Synchronization Annotations
  24. References
  25. Index

FAQ

《Java并发编程实践》和《Java并发编程实战》是同一本书吗?
是同一本英文原著《Java Concurrency in Practice》的不同中文版:电子工业出版社 2007 年版译名为“实践”,译者为韩锴、方秒,ISBN 9787121043161;机械工业出版社 2012 年版译名为“实战”,译者童云兰,ISBN 9787111370048,豆瓣评分约 9.0。
这本书的六个作者是什么背景?
六人均为 Java Community Process 中 JSR 166(并发工具)专家组的主要成员,也就是说 java.util.concurrent 包的设计与规范出自他们之手。Brian Goetz 后来成为 Oracle 的 Java 语言架构师,Joshua Bloch 是《Effective Java》的作者,Doug Lea 则是并发编程领域的学者。
书中内容是否已经过时,还能读吗?
书基于 Java SE 5/6 编写,没有涉及 CompletableFuture、Fork-Join 之外的虚拟线程等新特性,但对线程安全、内存模型、锁与无锁算法、线程池原理的论述仍是该领域最扎实的内容,作为基础教材完全不过时,阅读后再补充新版本 JDK 的并发特性即可。
阅读前需要怎样的 Java 基础?
建议熟悉 Java 语法、集合框架、异常与泛型,最好写过 SimpleDateFormat 共享、静态变量计数之类的多线程代码或至少接触过 synchronized 与 Thread。若完全没接触过多线程,可先读一本 Java 入门书中线程章节再回来。
这本书有配套源码或练习吗?
英文原书提供示例代码包(jcip-examples-src),中文版在开头列出代码清单,正文中的示例基本都可对应运行。书中没有习题册,建议把每章的“危险示例”自己复现,再做修复实验。

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