The authors assert that the increase in multi-core processors changes the game, such that soon even on entry level systems, your code will need to be multi-threaded to have any chance of being able to use all of the processing power you're paying for. So techniques that used to be something needed only by high-end server-side programmers will increasingly become part of every Java programmer's basic skillset.
Java 5.0 saw a major reworking of the threading facilities available to the Java programmer. If you need to write or support threaded code on Java, I'd consider this book a must-have. The authors are the primary members of the Expert Group responsible for the Java 5.0 java.util.concurrent packages. The level of detail here is excellent — not just an overview of new Java APIs, but a tutorial on threading concepts that is very clear, richly detailed, and fully supported by examples. The book doesn't suffer from having multiple authors — there is a consistent voice throughout, so either the authors worked very closely together or great editorial work was done to ensure a consistent tone.
Here's just a small sample some of the things you'll learn
- what's the difference between monitors, locks, latches, semaphores
- why double-check locking is broken
- why not to start a thread from a constructor
- why GUI event dispatch loops are single-threaded
- use (and mis-use) of volatile
- various ways in which multithreaded code can deadlock; techniques for avoiding or backing out of a deadlock
- how multi-threaded code interacts with exception handling, finalizers, and interruptions
- understanding the Java Memory Model and object visibility (when changes made to an object by one thread will be seen by other threads)
The practical stuff in Part III (testing multi-threaded code, and performance) is especially welcome. There are several graphs that show performance of various implementation alternatives, which make a very convincing case that the 5.0 concurrency packages provide great out-of-the-box performance.
The writing is a joy to read; in addition to being clear and concise, it includes some humorous observations such as 'writing tests is an adventure in iterative specification discovery' and 'a thread-safe class is one that is no more broken in a concurrent environment than in a single-threaded environment'.
The book provides exhaustive coverage of new concurrency stuff in 5.0, such as
- Concurrent Collections
- Executor Framework, thread pools, Callable, FutureTask, Blocking Queues
- ReentrantLock, ReadWriteLock, Condition
- Atomic variables ("better volatiles")
- 1. Introduction
- I. Fundamentals
- 2. Thread Safety (atomicity, race conditions, locking, reentrancy, liveness)
- 3. Sharing objects
- 4. Composing objects
- 5. Building blocks (synchronized collections, iterators, concurrent collections, queues, synchronizers, semaphores, barriers)
- II. Structuring Concurrent Applications
- 6. Task Execution (the Executor framework, thread pools, queues)
- 7. Cancellation and Shutdown
- 8. Applying Thread Pools
- 9. GUI applications
- III. Liveness, Performance, and Testing
- 10. Avoiding Liveness Hazards
- 11. Performance and Scalability
- 12. Testing Concurrent Programs
- IV. Advanced Topics
- 13. Explicit Locks
- 14. Building Custom Synchronizers
- 15. Atomic Variables and Nonblocking Synchronization
- 16. The Java Memory Model
- A. Annotations for Concurrency
The book's website is here
Order it from Amazon.com "