Java Concurrency in Practice

Brian Goetz

出版时间

2006-05-18

ISBN

9780321349606

评分

★★★★★

标签

编程

书籍介绍

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

AI导读
核心看点
  • 系统讲解线程安全、原子性与可见性核心概念
  • 深入剖析Java内存模型及不可变对象设计
  • 提供构建高性能并发应用的最佳实践指南
适合谁读
  • Java开发者及并发编程初学者
  • 希望深入理解底层原理的高级程序员
  • 从事后端高并发系统设计的工程师
读前提醒
  • 强烈建议阅读英文原版,中文译本质量较差
  • 内容理论深度大,需结合代码实践反复研读
  • 重点掌握java.util.concurrent工具包用法
读者共识
  • Java并发编程领域的权威圣经级著作
  • 思路清晰,对并发设计模式讲解透彻
  • 虽出版较早,但核心原理至今仍极具价值

本导读基于书籍简介、目录、原文摘录、短评和书评生成,不等同于全文精读。

精彩摘录
  • "加锁机制既可以确保可见性又可以确保原子性,而 volatile 变量只能确保可见性。 当且仅当满足以下所有条件时,才应该使用 volatile 变量: - 对变量的写入操作不依赖变量的当前值,或者你能确保只有单个线程更新变量的值。 - 该变量不会与其它状态变量一起纳入到不变性条件中。 - 在访问变量时不需要加锁。"
  • "当满足以下条件时,对象才是不可变的: - 对象创建以后其状态就不可修改 - 对象的所有域都是 final 类型 - 对象时正确创建的(在对象的构造期间,this 引用没有逸出) 从技术上来看,不可变对象并不需要将其所有的域都声明为 final 类型,例如 String 就是这种情况,这就要对类的良性数据竞争情况做精确的分析,因此需要深入理解 Java 的内存模型。... 自己在编码时不要这么做。"
  • "对于计算密集的任务,在拥有 N 个处理器的系统上,当线程池大小为 N+1 时,通常能实现最优的利用率。(即使当计算密集型的线程偶尔由于页缺失故障或者其它原因而暂停时,这个“额外”的线程也能确保 CPU 的时钟周期不会被浪费。)对于包含 I/O 操作或者其它阻塞操作的任务,由于线程并不会一直执行,因此线程池的规模应该更大。 计算每个任务对该资源的需求量,然后用该资源的可用总量除以每个任务的需求量,所得结果就是线程池大小的上限。"
  • "当任务需要某种通过资源池来管理的资源时,例如数据库连接,那么线程池和资源池的大小将会相互影响。如果每个任务都需要一个数据库连接,那么连接池的大小就限制了线程池的大小。同样,当线程池中的任务是数据库连接的唯一使用者时,那么线程池的大小又将限制连接池的大小。"
  • "final域能确保初始化过程的安全性,从而可以不受限制的访问不可变对象,并在共享这些对象时无需同步。"
  • "只有当volatile变量能够简化实现和同步策略的验证时,才使用它们。当验证正确性必须推断可见性问题时,应该避免使用volatile变量。正确使用volatile变量的方式包括:用于确保它们所引用的对象的状态的可见性,或者用于标识重要的生命周期事件(比如初始化或关闭)的发生。"
  • "To publish an object safely, both the reference to the object and the object's state must be made visible to other threads at the same time. A properly constructed object can be safely published by: Initializing an object reference from a static initializer; Storing a reference to it into a volatile"
  • "Our goal is to give readers a set of design rules and mental models that make it easier—and more fun—to build correct, performant concurrent classes and applications in Java."
作者简介
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.
目录
Listings xii
Preface xvii
Chapter 1: Introduction 1
1.1 A (very) brief history of concurrency 1
1.2 Benefits of threads 3

显示全部
用户评论
Java并发编程必读书.
在并发的世界里,正确不容易~ 居然连全英文电子版都读完了!
很不错的关于并发编程的书籍,广度和深度都不错,可以关注书本的作者的一些文章或者博客,都很不错,特别是Doug Lea先生的。
java开发者必看!
工作必备,将并发系统的设计思路讲得很明白。
补债
Java开发必读,早两年读可以少走很多弯路…
信息量非常大,读起来很慢,适合写过多年并发程序后来读。PS: 中文版翻译非常烂。
看英文吧累,看中文吧看不懂,只能混着看。
Java必修课
收藏