具体描述
This book covers:
Basic concepts of concurrency and thread safety
Techniques for building and composing thread-safe classes
Using the concurrency building blocks in java.util.concurrent
Performance optimization dos and don'ts
Testing concurrent programs
Advanced topics such as atomic variables, nonblocking algorithms, and the Java Memory Model
作者简介
Brian Goetz is a software consultant with twenty years industry experience, with over 75 articles on Java development. He is one of the primary members of the Java Community Process JSR 166 Expert Group (Concurrency Utilities), and has served on numerous other JCP Expert Groups.
Tim Peierls is the very model of a modern multiprocessor, with BoxPop.biz, recording arts, and goings on theatrical. He is one of the primary members of the Java Community Process JSR 166 Expert Group (Concurrency Utilities), and has served on numerous other JCP Expert Groups.
Joshua Bloch is a principal engineer at Google and a Jolt Award-winner. He was previously a distinguished engineer at Sun Microsystems and a senior systems designer at Transarc. Josh led the design and implementation of numerous Java platform features, including JDK 5.0 language enhancements and the award-winning Java Collections Framework. He holds a Ph.D. in computer science from Carnegie Mellon University.
Joseph Bowbeer is a software architect at Vizrea Corporation where he specializes in mobile application development for the Java ME platform, but his fascination with concurrent programming began in his days at Apollo Computer. He served on the JCP Expert Group for JSR-166 (Concurrency Utilities).
David Holmes is director of DLTeCH Pty Ltd, located in Brisbane, Australia. He specializes in synchronization and concurrency and was a member of the JSR-166 expert group that developed the new concurrency utilities. He is also a contributor to the update of the Real-Time Specification for Java, and has spent the past few years working on an implementation of that specification.
Doug Lea is one of the foremost experts on object-oriented technology and software reuse. He has been doing collaborative research with Sun Labs for more than five years. Lea is Professor of Computer Science at SUNY Oswego, Co-director of the Software Engineering Lab at the New York Center for Advanced Technology in Computer Applications, and Adjunct Professor of Electrical and Computer Engineering at Syracuse University. In addition, he co-authored the book, Object-Oriented System Development (Addison-Wesley, 1993). He received his B.A., M.A., and Ph.D. from the University of New Hampshire.
目录信息
Preface xvii
Chapter 1: Introduction 1
1.1 A (very) brief history of concurrency 1
1.2 Benefits of threads 3
1.3 Risks of threads 5
1.4 Threads are everywhere 9
Part I: Fundamentals 13
Chapter 2: Thread Safety 15
2.1 What is thread safety? 17
2.2 Atomicity 19
2.3 Locking 23
2.4 Guarding state with locks 27
2.5 Liveness and performance 29
Chapter 3: Sharing Objects 33
3.1 Visibility 33
3.2 Publication and escape 39
3.3 Thread confinement 42
3.4 Immutability 46
3.5 Safepublication 49
Chapter 4: Composing Objects 55
4.1 Designing a thread-safe class 55
4.2 Instance confinement 58
4.3 Delegating thread safety 62
4.4 Adding functionality to existing thread-safe classes 71
4.5 Documenting synchronization policies 74
Chapter 5: Building Blocks 79
5.1 Synchronized collections 79
5.2 Concurrent collections 84
5.3 Blocking queues and the producer-consumer pattern 87
5.4 Blocking and interruptible methods 92
5.5 Synchronizers 94
5.6 Building an efficient, scalable result cache 101
Part II: Structuring Concurrent Applications 111
Chapter 6: Task Execution 113
6.1 Executing tasks in threads 113
6.2 The Executor framework 117
6.3 Finding exploitable parallelism 123
Chapter 7: Cancellation and Shutdown 135
7.1 Task cancellation 135
7.2 Stopping a thread-based service 150
7.3 Handling abnormal thread termination 161
7.4 JVM shutdown 164
Chapter 8: Applying Thread Pools 167
8.1 Implicit couplings between tasks and execution policies 167
8.2 Sizing thread pools 170
8.3 Configuring ThreadPoolExecutor 171
8.4 Extending ThreadPoolExecutor 179
8.5 Parallelizing recursive algorithms 181
Chapter 9: GUI Applications 189
9.1 Why are GUIs single-threaded? 189
9.2 Short-running GUI tasks 192
9.3 Long-running GUI tasks 195
9.4 Shared data models 198
9.5 Other forms of single-threaded subsystems 202
Part III: Liveness, Performance, and Testing 203
Chapter 10: Avoiding Liveness Hazards 205
10.1 Deadlock 205
10.2 Avoiding and diagnosing deadlocks 215
10.3 Other liveness hazards 218
Chapter 11: Performance and Scalability 221
11.1 Thinking about performance 221
11.2 Amdahl's law 225
11.3 Costs introduced by threads 229
11.4 Reducing lock contention 232
11.5 Example: Comparing Map performance 242
11.6 Reducing context switch overhead 243
Chapter 12: Testing Concurrent Programs 247
12.1 Testing for correctness 248
12.2 Testing for performance 260
12.3 Avoiding performance testing pitfalls 266
12.4 Complementary testing approaches 270
Part IV: Advanced Topics 275
Chapter 13: Explicit Locks 277
13.1 Lock and ReentrantLock 277
13.2 Performance considerations 282
13.3 Fairness 283
13.4 Choosing between synchronized and ReentrantLock 285
13.5 Read-write locks 286
Chapter 14: Building Custom Synchronizers 291
14.1 Managing state dependence 291
14.2 Using condition queues 298
14.3 Explicit condition objects 306
14.4 Anatomy of a synchronizer 308
14.5 AbstractQueuedSynchronizer 311
14.6 AQS in java.util.concurrent synchronizer classes 314
Chapter15: Atomic Variables and Nonblocking Synchronization 319
15.1 Disadvantages of locking 319
15.2 Hardware support for concurrency 321
15.3 Atomic variable classes 324
15.4 Nonblocking algorithms 329
Chapter 16: The Java Memory Model 337
16.1 What is a memory model, and why would I want one? 337
16.2 Publication 344
16.3 Initialization safety 349
Appendix A: Annotations for Concurrency 353
A.1 Class annotations 353
A.2 Field andmethod annotations 353
Bibliography 355
Index 359
· · · · · · (收起)
读后感
我看过的书不算少, 但是本书是对我帮助最大的. 由于本书难度较高, 不好翻译, 中文版的质量也确实让人不敢恭维. 因此只好硬着头皮啃完英文原版. 当翻完最后一页的时候, 我知道从此之后不会再对英文技术书籍抱有恐惧, 这是我最大的收获. 另外, 从书中学到的知识也很有用, 经常...
整体上还是可以看的,不过很多地方看不懂只是因为翻译不恰当。 这本书本身值五颗星。 译文: 一个对象是否需要是线程安全的,取决于它是否被多个线程访问。这指的是程序中访问对象的方式,而不是对象要实现的功能。 原文: Whether an object needs to be thread‐safe depen...
总体翻译后读起来还是比较顺畅 章节安排,实例演示说明很到位 虽然有些概念不是太深入,但是足矣应付大多数的开发需求 确实实战方面多一些 幸好手头有相关的案例,可以直接修改模拟使用,挺好 Java方面,这是至今看过比较赞的书了! 超值!
这本书原版写的很好 但是翻译的太差了 字都认识 连起来不了解 你在逗我 三星给原版 我要去读原版了 即使读的很慢 也比不懂强 翻译 你能用点心不 翻译的什么鬼 翻译的时候能自己先读一读可好 翻译成这样 真是害人 里面的内容不错 就是有点老了 讲的是Java6之前的内容 可以先把此...
终于读完,对于原著英文版来说,绝对是力荐的。看看作者列表,一个个响亮的名字,这本书的价值就不言而喻了。可贵的是书中不仅仅是详细介绍了jdk5引入的concurrent包的使用和基本原理,并且对线程安全性的设计、性能、死锁和可伸缩性的讨论也蕴含着丰富实践经验。中文版翻...
用户评价
这是一部需要反复阅读才能真正消化的巨著。我第一次通读时,更多的是在“吸收知识点”,但接下来的几次翻阅,则是在“印证实践”。每当我遇到新的并发难题,比如在某个高负载服务中出现了间歇性的数据不一致,我都会习惯性地翻开它,往往能在其中找到对应的原理阐述和解决方案的雏形。书中的案例研究部分尤其精彩,它们不像教科书那样完美,而是充满了真实世界的妥协和限制,这使得它提供的建议极具操作性。阅读这本书,你会发现很多流行的并发框架和工具,其背后的设计理念都可以在这里找到源头。它教会我的最宝贵的一课是如何“防患于未然”,而不是事后诸葛亮。如果你期待一本能让你在周末轻松读完并掌握所有技巧的书,那请绕道。但如果你愿意投入时间和精力,去挖掘并发编程这座宝藏的最深处,那么,这本书就是你手中最可靠的镐和指南针。它带来的知识沉淀,是任何短期教程都无法比拟的。
这本书简直是并发编程领域的“圣经”,我第一次捧起它的时候,就被那种严谨、深入的专业性给震慑住了。它不像市面上很多那种浮于表面的技术书籍,仅仅罗列API的使用方法,而是真正地剖析了并发设计的底层逻辑和陷阱。作者们显然是实战经验极其丰富的大师,他们没有满足于解释“如何做”,而是花费了大量的篇幅去解释“为什么必须这样做”,以及不这样做的后果是什么。比如,书中对JUC包中那些核心类的设计哲学解读,简直是拨云见日。我记得有一章详细讲了`ReentrantLock`与`synchronized`在特定场景下的性能权衡和语义差异,那种对内存模型和JVM规范的深刻理解,让我这个自认为对并发有所涉猎的开发者都感到汗颜。阅读过程需要极高的专注度,因为它不是用来快速浏览的,而是需要停下来思考、对照代码、甚至在脑海中模拟线程交错的。每当我感觉理解了某个概念时,作者总能抛出一个更深层次的陷阱或优化点来挑战我的认知。这本书是真正意义上的“实践指南”,它教会我的不是套路,而是构建健壮并发系统的思维框架。如果你想在多线程世界里站稳脚跟,这本书是绕不过去的。
说实话,这本书的阅读体验并不轻松,它更像是一次对思维的“高强度拉力训练”。我不是说它的文字晦涩难懂,而是它所涵盖的内容密度实在太高了。我经常需要一边对照官方文档和JDK源码,一边阅读,否则那些抽象的概念,比如原子性、可见性、有序性在没有具体代码支撑时,很容易在脑海中形成一团乱麻。作者对并发编程中的各种设计模式,如生产者-消费者模型、读写锁的定制化实现等,讲解得极其透彻,但同时,他们也毫不留情地揭示了这些模式在实际工程中可能遇到的性能瓶颈和死锁风险。这使得这本书的价值非常高,因为它不仅告诉你“最好的做法是什么”,更重要的是,它会告诉你“大多数人会犯的错误是什么,以及为什么那些错误如此隐蔽”。我尤其欣赏其中关于并发工具类的源码解析部分,那简直是一次对JUC作者思维模式的逆向工程学习。读完后,我对构建高性能、高可靠性的分布式服务系统有了全新的认识,感觉自己的代码审查能力都得到了质的飞跃,看一眼别人的并发代码,就能嗅到潜在的风险点。
这本书的结构编排堪称教科书级别,逻辑层层递进,像一个精心设计的迷宫,每解开一个机关,都会通往更深、更精彩的领域。它并非一开始就抛出复杂的并发集合类,而是从最基础的内存模型和happens-before原则讲起,构建起坚实的理论基础。这种循序渐进的方式,极大地降低了理解并发编程的陡峭曲线。我特别喜欢作者在讲解每一个并发机制时,都会配上一个清晰的、足以说明问题的代码示例,这些例子往往非常精妙,用最少的代码量展示了最核心的问题所在。特别是关于线程池的调优和生命周期管理的章节,简直是救了我好几次命。过去我对线程池的参数设置总是凭感觉,读了这本书后,才明白每个参数背后都对应着特定的业务场景和资源约束。这本书的权威性毋庸置疑,它已经超越了一本普通的编程指南,更像是一份关于如何设计可扩展、可维护的并发系统的宣言。对于希望从“会写多线程”跨越到“会设计并发系统”的工程师来说,这是必不可少的案头工具书。
坦白讲,如果你的并发知识还停留在仅仅会用`Thread.start()`或者`Runnable`的初级阶段,这本书可能会让你感到挫败。它要求的读者具备一定的编程经验和对计算机底层原理的好奇心。它对各种“陷阱”的描述,常常让我有一种“原来我一直都错了”的顿悟感。比如,关于伪共享(False Sharing)的讨论,如果不读这本书,我可能永远不会意识到CPU缓存行对程序性能的影响竟然如此巨大,尤其是在高频交易或数据密集型应用中。作者们对待细节的痴迷程度令人敬佩,他们似乎把Java语言规范中关于并发的每一个角落都挖掘了个底朝天,然后用极其清晰的语言将其重构,呈现在读者面前。这本书的最大价值在于,它让你对“并行”和“并发”这两个词有了真正成熟的理解,不再是简单的代码堆砌,而是一种系统级的架构思考。它帮助我建立起一套评判任何并发方案优劣的客观标准,而不是人云亦云地追随最新的框架。
仔细看了遍原版,真心写的很深入!很有帮助。 201605
pdf档
目前还没碰到过复杂的使用场景
不搞java了,所以应该不会再读了。书倒是好书。
cf. "Concurrency: State Models & Java Programs"