9780321349606

Java Concurrency in Practice

by ; ; ; ; ;
  • ISBN13:

    9780321349606

  • ISBN10:

    0321349601

  • Edition: 1st
  • Format: Paperback
  • Copyright: 1/1/2006
  • Publisher: Addison-Wesley Professional
  • Purchase Benefits
  • Free Shipping On Orders Over $59!
    Your order must be $59 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $59.99 Save up to $9.00
  • Buy New
    $50.99

    CURRENTLY AVAILABLE, USUALLY SHIPS IN 24-48 HOURS

Supplemental Materials

What is included with this book?

  • The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.
  • The eBook copy of this book is not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Summary

A how-to companion to Doug Lea's 'Concurrent Programming in Java', this book is the only authorative and practical guide to Java Concurrency.

Author Biography

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.



Table of Contents

Listings
xii
Preface xvii
Introduction
1(12)
A (very) brief history of concurrency
1(2)
Benefits of threads
3(2)
Risks of threads
5(4)
Threads are everywhere
9(4)
I. Fundamentals
13(98)
Thread Safety
15(18)
What is thread safety?
17(2)
Atomicity
19(4)
Locking
23(4)
Guarding state with locks
27(2)
Liveness and performance
29(4)
Sharing Objects
33(22)
Visibility
33(6)
Publication and escape
39(3)
Thread confinement
42(4)
Immutability
46(3)
Safe publication
49(6)
Composing Objects
55(24)
Designing a thread-safe class
55(3)
Instance confinement
58(4)
Delegating thread safety
62(9)
Adding functionality to existing thread-safe classes
71(3)
Documenting synchronization policies
74(5)
Building Blocks
79(32)
Synchronized collections
79(5)
Concurrent collections
84(3)
Blocking queues and the producer-consumer pattern
87(5)
Blocking and interruptible methods
92(2)
Synchronizers
94(7)
Building an efficient, scalable result cache
101(10)
II. Structuring Concurrent Applications
111(92)
Task Execution
113(22)
Executing tasks in threads
113(4)
The Executor framework
117(6)
Finding exploitable parallelism
123(12)
Cancellation and Shutdown
135(32)
Task cancellation
135(15)
Stopping a thread-based service
150(11)
Handling abnormal thread termination
161(3)
JVM shutdown
164(3)
Applying Thread Pools
167(22)
Implicit couplings between tasks and execution policies
167(3)
Sizing thread pools
170(1)
Configuring ThreadPoolExecutor
171(8)
Extending ThreadPoolExecutor
179(2)
Parallelizing recursive algorithms
181(8)
GUI Applications
189(14)
Why are GUIs single-threaded?
189(3)
Short-running GUI tasks
192(3)
Long-running GUI tasks
195(3)
Shared data models
198(4)
Other forms of single-threaded subsystems
202(1)
III. Liveness, Performance, and Testing
203(72)
Avoiding Liveness Hazards
205(16)
Deadlock
205(10)
Avoiding and diagnosing deadlocks
215(3)
Other liveness hazards
218(3)
Performance and Scalability
221(26)
Thinking about performance
221(4)
Amdahl's law
225(4)
Costs introduced by threads
229(3)
Reducing lock contention
232(10)
Example: Comparing Map performance
242(1)
Reducing context switch overhead
243(4)
Testing Concurrent Programs
247(28)
Testing for correctness
248(12)
Testing for performance
260(6)
Avoiding performance testing pitfalls
266(4)
Complementary testing approaches
270(5)
IV. Advanced Topics
275(78)
Explicit Locks
277(14)
Lock and ReentrantLock
277(5)
Performance considerations
282(1)
Fairness
283(2)
Choosing between synchronized and ReentrantLock
285(1)
Read-write locks
286(5)
Building Custom Synchronizers
291(28)
Managing state dependence
291(7)
Using condition queues
298(8)
Explicit condition objects
306(2)
Anatomy of a synchronizer
308(3)
AbstractQueuedSynchronizer
311(3)
AQS in java.util.concurrent synchronizer classes
314(5)
Atomic Variables and Nonblocking Synchronization
319(18)
Disadvantages of locking
319(2)
Hardware support for concurrency
321(3)
Atomic variable classes
324(5)
Nonblocking algorithms
329(8)
The Java Memory Model
337(16)
What is a memory model, and why would I want one?
337(7)
Publication
344(5)
Initialization safety
349(4)
A. Annotations for Concurrency
353(2)
Class annotations
353(1)
Field and method annotations
353(2)
Bibliography 355(4)
Index 359

Excerpts

At this writing, multicore processors are just now becoming inexpensive enough for midrange desktop systems. Not coincidentally, many development teams are noticing more and more threading-related bug reports in their projects. In a recent post on the NetBeans developer site, one of the core maintainers observed that a single class had been patched over 14 times to fix threading-related problems. Dion Almaer, former editor of TheServerSide, recently blogged (after a painful debugging session that ultimately revealed a threading bug) that most Java programs are so rife with concurrency bugs that they work only "by accident". Indeed, developing, testing and debugging multithreaded programs can be extremely difficult because concurrency bugs do not manifest themselves predictably. And when they do surface, it is often at the worst possible time--in production, under heavy load. One of the challenges of developing concurrent programs in Java is the mismatch between the concurrency features offered by the platform and how developers need to think about concurrency in their programs. The language provides low-level mechanisms such as synchronization and condition waits, but these mechanisms must be used consistently to implement application-level protocols or policies. Without such policies, it is all too easy to create programs that compile and appear to work but are nevertheless broken. Many otherwise excellent books on concurrency fall short of their goal by focusing excessively on low-level mechanisms and APIs rather than design-level policies and patterns. Java 5.0 is a huge step forward for the development of concurrent applications in Java, providing new higher-level components and additional low-level mechanisms that make it easier for novices and experts alike to build concurrent applications. The authors are the primary members of the JCP Expert Group that created these facilities; in addition to describing their behavior and features, we present the underlying design patterns and anticipated usage scenarios that motivated their inclusion in the platform libraries. 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. We hope you enjoy Java Concurrency in Practice. Brian Goetz Williston, VT March 2006 How to use this book To address the abstraction mismatch between Java's low-level mechanisms and the necessary design-level policies, we present a simplified set of rules for writing concurrent programs. Experts may look at these rules and say "Hmm, that's not entirely true: class C is thread-safe even though it violates rule R." While it is possible to write correct programs that break our rules, doing so requires a deep understanding of the low-level details of the Java Memory Model, and we want developers to be able to write correct concurrent programs without having to master these details. Consistently following our simplified rules will produce correct and maintainable concurrent programs. We assume the reader already has some familiarity with the basic mechanisms for concurrency in Java. Java Concurrency in Practice is not an introduction to concurrency--for that, see the threading chapter of any decent introductory volume, such as The Java Programming Language (Arnold et al., 2005). Nor is it an encyclopedic reference for All Things Concurrency--for that, see Concurrent Programming in Java (Lea, 2000). Rather, it offers practical design rules to assist developers in the difficult process of creating safe and performant concurrent classes. Where appropriate, we cross-reference relevant sections of The Java Programming Language, Concurrent Programming in Java, The Java Language Specification (Gosling et al., 2005), and Effective Java (Bloch, 2001) usi

Rewards Program

Write a Review