Java Concurrency Programming: From Beginner to Mastery cover

Java Concurrency Programming: From Beginner to Mastery

No rating yet
Chapters
11
ISBN
9787302401919

Tags

Summary

Published by Tsinghua University Press in July 2015, this book draws on author Zhang Zhenhua's more than ten years of frontline experience in Java development and concurrent programming to break the notoriously difficult topic of concurrency into three stages—fundamentals, advanced topics, and application—in about 216 pages, aiming to be compact, straightforward, and practical. The content begins with the most easily confused concepts: the relationship between CPU cores and thread counts, CPU time-slice rotation, the difference between processes and threads, parallelism and concurrency, the difference between throughput and concurrency level, and the value and risks of high-concurrency programming. It then moves on to Java threads themselves: the three ways to create a thread, common properties and methods of the Thread class, the interruption mechanism, the thread lifecycle, daemon threads, thread groups, ThreadLocal, and thread exception handling. The third part addresses the real difficulty of concurrent programming—thread safety. Starting from the Java memory model, the book explains how "unsafety" actually occurs, then introduces in turn the implicit lock synchronized, Lock and ReentrantLock, ReadWriteLock and ReentrantReadWriteLock, StampedLock, the causes and avoidance of deadlock, the volatile keyword, atomic classes, and several ways of writing the singleton pattern. On this basis it goes on to discuss thread-safe collection classes such as Hashtable, ConcurrentHashMap, CopyOnWriteArrayList, CopyOnWriteArraySet, and Vector, and explains the applicable boundaries of the copy-on-write mechanism. The final part brings the knowledge into engineering practice: the principles and configuration of thread pools, the Fork/Join framework, the practical application of threads and thread pools in internet projects, Tomcat thread pool settings, thread monitoring and thread analysis, and thread usage in Android. The book is restrained in length, pairs knowledge points with code examples, and is suitable both as a first systematic book on concurrent programming and as a reference manual for daily consultation.

Editor's review

市面上的Java并发书大致分两类:一类是《Java并发编程实战》这样的权威经典,分量足但术语密度高,初学者容易卡在头两章;另一类是动辄六七百页的“大砖头”,买回来多半用来垫显示器。这本书恰好填了中间的空档——216页,两天能通读一遍,但该讲的点一个没落下。 它的写法很“工程化”:先讲CPU核心数、时间片轮转、进程与线程这些底层概念,再讲Thread的API与生命周期,然后才进入内存模型与各种锁。这个顺序的好处是,读者不会在还不知道“线程怎么被调度”的情况下就硬啃happens-before。锁的部分覆盖得比同篇幅的书更全,从synchronized、ReentrantLock一路讲到StampedLock与原子类,还把单例模式的各种写法作为线程安全的落地例子,很实用。 另外两处值得称道:一是专门用一章讲线程安全的集合类与CopyOnWrite机制的适用边界,二是把线程池、Fork/Join、Tomcat线程池配置和线程监控分析连成一条线,直接对接互联网项目现场。书中还留了Android线程应用一章,照顾到了移动端读者。 需要提醒的是,本书成书于2015年,示例基于当时的JDK,作者本人也坦承限于篇幅未对并发技术做全景式展开、代码注释相对简略。它更适合作为“第一本系统的并发书”和“随时翻查的参考手册”,而不是终点。读完它再上《Java并发编程实战》和《Java并发编程的艺术》补原理深度,是一条顺畅的路径。

Who it's for

A good fit for

  • 有Java语法基础、正准备系统学习多线程与并发编程的开发者
  • 需要应对Java后端面试、想快速补齐并发知识点的求职者
  • 已会用线程池和synchronized,但说不清原理与注意事项的工程师
  • 讲授Java程序设计课程、需要一本薄而全参考书的高校师生

Not a good fit for

  • 完全没有Java基础、尚未写过类和对象的纯新手,建议先补语言基础
  • 希望深入JVM源码、CPU缓存一致性协议与AQS实现细节的资深读者
  • 需要覆盖Java 8之后CompletableFuture、虚拟线程等新特性的读者

Reading tips

  1. 按第1部分到第3部分的顺序通读一遍(约两三天),先建立“概念—线程—安全—工具—应用”的整体地图
  2. 每读一个知识点就动手写小demo复现,尤其是中断、死锁、锁升级与线程池拒绝策略
  3. 把第4章集合类与第6章线程池作为重点,结合自己项目中的配置对照阅读,注意CopyOnWrite与线程池参数的适用边界
  4. 读完本书后接《Java并发编程实战》或《Java并发编程的艺术》补原理深度,并留意新版JDK带来的并发新特性

About the publisher

Tsinghua University Press China · Founded in 1980

Founded in 1980, Tsinghua University Press has 57 titles in our collection, covering popular science, medicine, health, law, philosophy and social sciences. Representative works include medical popular-science books such as Cancer Truth: Doctors Are Reading It Too and New Knowledge on Cancer by Bo Luo (Li Zhizhong), legal titles such as Sunshine Is the Best Preservative: Express Delivery of Major Global Anti-Corruption Cases, and works like Qi Ge's A Brief History of Philosophy with Big Ideas and Liu Yunhao's From the Internet to a New Industrial Revolution. Its authors include science writers, medical researchers, the Renmin University of China anti-corruption master's class and university scholars, reflecting a publishing profile that balances academic seriousness with accessible reading. As public information is limited, this profile is based only on the titles in our collection.

Contents

  1. Part 1 Fundamentals of Thread Concurrency
  2. Chapter 1 Concepts: CPU Cores and Thread Count; CPU Time-Slice Rotation; Processes and Threads; Parallelism and Concurrency; Throughput; The Significance and Pitfalls of High-Concurrency Programming
  3. Chapter 2 Understanding Thread in Java: Three Ways to Implement a Thread; Thread Attributes and Methods; Thread Interruption; Thread Lifecycle; Daemon Threads; Thread Groups; ThreadLocal; Thread Exception Handling
  4. Chapter 3 Thread Safety: The Java Memory Model and Multithreading; Unsafe vs. Safe; synchronized; Lock and ReentrantLock; ReadWriteLock and ReentrantReadWriteLock; StampedLock; Deadlock; volatile; Atomic Operations; Writing the Singleton Pattern
  5. Chapter 4 Thread-Safe Collection Classes: Hashtable; ConcurrentHashMap; CopyOnWriteArrayList; CopyOnWriteArraySet; The CopyOnWrite Mechanism; Vector and More
  6. Chapter 5 Thread Valves
  7. Chapter 6 Thread Pools
  8. Chapter 7 The Fork/Join Framework
  9. Chapter 8 Threads and Thread Pools in Internet Project Development
  10. Chapter 9 Thread Monitoring and Thread Analysis
  11. Chapter 10 Threading in Android Applications

FAQ

这本书适合零基础学Java的人看吗?
不太适合。书中默认读者已经会写Java类、了解基本语法与集合,开篇就直接讨论线程创建、内存模型与锁机制。建议先掌握Java语言基础和面向对象,再来读这本。
书里的例子用的是哪个Java版本?现在还能用吗?
本书2015年出版,示例基于当时的JDK版本,核心API如Thread、synchronized、ReentrantLock、ThreadPoolExecutor、ForkJoinPool至今仍是并发编程的基础,可以直接运行和理解;但CompletableFuture、虚拟线程等较新特性书中没有覆盖,需要另外补充。
这本书和《Java并发编程实战》有什么区别?
《Java并发编程实战》由JSR 166专家组成员撰写,偏重并发设计与最佳实践,理论深度高但中文术语较晦涩;本书篇幅更短(216页),按概念、线程、线程安全、集合类、线程池、Fork/Join、实际应用的顺序讲,更适合作为第一本入门书。两者可以前后衔接阅读。
书中讲的“线程阀”是什么?
线程阀是作者对控制线程并发访问量、对并发请求进行限流与协调的一类同步工具的统称,书中单列一章讨论。它与Semaphore信号量、CountDownLatch等JDK并发工具的用途相近,阅读时可结合java.util.concurrent包中的相关类一起理解。
看完这本书能达到什么水平?
能系统掌握线程生命周期、线程安全与常见锁、线程安全集合、线程池配置和Fork/Join的基本用法,并了解线程监控与分析方法,应对初中级Java岗位的并发面试基本够用;若要冲击更高阶岗位,还需补充JMM底层、AQS源码与高并发系统设计方面的内容。

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