Java Concurrency in Practice

Book description

"I was fortunate indeed to have worked with a fantastic team on the design and implementation of the concurrency features added to the Java platform in Java 5.0 and Java 6. Now this same team provides the best explanation yet of these new features, and of concurrency in general. Concurrency is no longer a subject for advanced users only. Every Java developer should read this book."

--Martin Buchholz

JDK Concurrency Czar, Sun Microsystems

"For the past 30 years, computer performance has been driven by Moore’s Law; from now on, it will be driven by Amdahl’s Law. Writing code that effectively exploits multiple processors can be very challenging. Java Concurrency in Practice provides you with the concepts and techniques needed to write safe and scalable Java programs for today’s--and tomorrow’s--systems."

--Doron Rajwan

Research Scientist, Intel Corp

"This is the book you need if you’re writing--or designing, or debugging, or maintaining, or contemplating--multithreaded Java programs. If you’ve ever had to synchronize a method and you weren’t sure why, you owe it to yourself and your users to read this book, cover to cover."

--Ted Neward

Author of Effective Enterprise Java

"Brian addresses the fundamental issues and complexities of concurrency with uncommon clarity. This book is a must-read for anyone who uses threads and cares about performance."

--Kirk Pepperdine

CTO, JavaPerformanceTuning.com

"This book covers a very deep and subtle topic in a very clear and concise way, making it the perfect Java Concurrency reference manual. Each page is filled with the problems (and solutions!) that programmers struggle with every day. Effectively exploiting concurrency is becoming more and more important now that Moore’s Law is delivering more cores but not faster cores, and this book will show you how to do it."

--Dr. Cliff Click

Senior Software Engineer, Azul Systems

"I have a strong interest in concurrency, and have probably written more thread deadlocks and made more synchronization mistakes than most programmers. Brian’s book is the most readable on the topic of threading and concurrency in Java, and deals with this difficult subject with a wonderful hands-on approach. This is a book I am recommending to all my readers of The Java Specialists’ Newsletter, because it is interesting, useful, and relevant to the problems facing Java developers today."

--Dr. Heinz Kabutz

The Java Specialists’ Newsletter

"I’ve focused a career on simplifying simple problems, but this book ambitiously and effectively works to simplify a complex but critical subject: concurrency. Java Concurrency in Practice is revolutionary in its approach, smooth and easy in style, and timely in its delivery--it’s destined to be a very important book."

--Bruce Tate

Author of Beyond Java

"Java Concurrency in Practice is an invaluable compilation of threading know-how for Java developers. I found reading this book intellectually exciting, in part because it is an excellent introduction to Java’s concurrency API, but mostly because it captures in a thorough and accessible way expert knowledge on threading not easily found elsewhere."

--Bill Venners

Author of Inside the Java Virtual Machine

Threads are a fundamental part of the Java platform. As multicore processors become the norm, using concurrency effectively becomes essential for building high-performance applications. Java SE 5 and 6 are a huge step forward for the development of concurrent applications, with improvements to the Java Virtual Machine to support high-performance, highly scalable concurrent classes and a rich set of new concurrency building blocks. In Java Concurrency in Practice, the creators of these new facilities explain not only how they work and how to use them, but also the motivation and design patterns behind them.

However, developing, testing, and debugging multithreaded programs can still be very difficult; it is all too easy to create concurrent programs that appear to work, but fail when it matters most: in production, under heavy load. Java Concurrency in Practice arms readers with both the theoretical underpinnings and concrete techniques for building reliable, scalable, maintainable concurrent applications. Rather than simply offering an inventory of concurrency APIs and mechanisms, it provides design rules, patterns, and mental models that make it easier to build concurrent programs that are both correct and performant.

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

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Contents
  5. Listings
  6. Preface
  7. 1 Introduction
    1. 1.1 A (very) brief history of concurrency
    2. 1.2 Benefits of threads
    3. 1.3 Risks of threads
    4. 1.4 Threads are everywhere
  8. I Fundamentals
    1. 2 Thread Safety
      1. 2.1 What is thread safety?
      2. 2.2 Atomicity
      3. 2.3 Locking
      4. 2.4 Guarding state with locks
      5. 2.5 Liveness and performance
    2. 3 Sharing Objects
      1. 3.1 Visibility
      2. 3.2 Publication and escape
      3. 3.3 Thread confinement
      4. 3.4 Immutability
      5. 3.5 Safe publication
    3. 4 Composing Objects
      1. 4.1 Designing a thread-safe class
      2. 4.2 Instance confinement
      3. 4.3 Delegating thread safety
      4. 4.4 Adding functionality to existing thread-safe classes
      5. 4.5 Documenting synchronization policies
    4. 5 Building Blocks
      1. 5.1 Synchronized collections
      2. 5.2 Concurrent collections
      3. 5.3 Blocking queues and the producer-consumer pattern
      4. 5.4 Blocking and interruptible methods
      5. 5.5 Synchronizers
      6. 5.6 Building an efficient, scalable result cache
  9. II Structuring Concurrent Applications
    1. 6 Task Execution
      1. 6.1 Executing tasks in threads
      2. 6.2 The Executor framework
      3. 6.3 Finding exploitable parallelism
    2. 7 Cancellation and Shutdown
      1. 7.1 Task cancellation
      2. 7.2 Stopping a thread-based service
      3. 7.3 Handling abnormal thread termination
      4. 7.4 JVM shutdown
    3. 8 Applying Thread Pools
      1. 8.1 Implicit couplings between tasks and execution policies
      2. 8.2 Sizing thread pools
      3. 8.3 Configuring ThreadPoolExecutor
      4. 8.4 Extending ThreadPoolExecutor
      5. 8.5 Parallelizing recursive algorithms
    4. 9 GUI Applications
      1. 9.1 Why are GUIs single-threaded?
      2. 9.2 Short-running GUI tasks
      3. 9.3 Long-running GUI tasks
      4. 9.4 Shared data models
      5. 9.5 Other forms of single-threaded subsystems
  10. III Liveness, Performance, and Testing
    1. 10 Avoiding Liveness Hazards
      1. 10.1 Deadlock.
      2. 10.2 Avoiding and diagnosing deadlocks
      3. 10.3 Other liveness hazards
    2. 11 Performance and Scalability
      1. 11.1 Thinking about performance
      2. 11.2 Amdahl's law
      3. 11.3 Costs introduced by threads
      4. 11.4 Reducing lock contention
      5. 11.5 Example: Comparing Map performance
      6. 11.6 Reducing context switch overhead
    3. 12 Testing Concurrent Programs
      1. 12.1 Testing for correctness
      2. 12.2 Testing for performance
      3. 12.3 Avoiding performance testing pitfalls
      4. 12.4 Complementary testing approaches
  11. IV Advanced Topics
    1. 13 Explicit Locks
      1. 13.1 Lock and ReentrantLock
      2. 13.2 Performance considerations
      3. 13.3 Fairness
      4. 13.4 Choosing between synchronized and ReentrantLock
      5. 13.5 Read-write locks
    2. 14 Building Custom Synchronizers
      1. 14.1 Managing state dependence
      2. 14.2 Using condition queues
      3. 14.3 Explicit condition objects
      4. 14.4 Anatomy of a synchronizer
      5. 14.5 AbstractQueuedSynchronizer
      6. 14.6 AQS in java.util.concurrent synchronizer classes
    3. 15 Atomic Variables and Nonblocking Synchronization
      1. 15.1 Disadvantages of locking
      2. 15.2 Hardware support for concurrency
      3. 15.3 Atomic variable classes
      4. 15.4 Nonblocking algorithms
    4. 16 The Java Memory Model
      1. 16.1 What is a memory model, and why would I want one?
      2. 16.2 Publication
      3. 16.3 Initialization safety
  12. A Annotations for Concurrency
    1. A.1 Class annotations
    2. A.2 Field and method annotations
  13. Bibliography
  14. Index

Product information

  • Title: Java Concurrency in Practice
  • Author(s): Brian Goetz, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, Doug Lea
  • Release date: May 2006
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 0321349601