Concurrency Utilities
So far in this chapter, we’ve demonstrated how to create and
synchronize threads at a low level, using Java language primitives. The
java.util.concurrent
package and subpackages introduced with Java 5.0 build on this
functionality, adding important threading utilities and codifying some
common design patterns by supplying standard implementations. Roughly in
order of generality, these areas include:
- Thread-aware Collections implementations
The
java.util.concurrentpackage augments the Java Collections API with several implementations for specific threading models. These include timed wait and blocking implementations of theQueueinterface, as well as nonblocking, concurrent-access optimized implementations of theQueueandMapinterfaces. The package also adds “copy on write”ListandSetimplementations for extremely efficient “almost always read” cases. These may sound complex, but actually cover some fairly simple cases very well. We’ll cover the Collections API in Chapter 11.- Executors
Executors run tasks, includingRunnables, and abstract the concept of thread creation and pooling from the user. Executors are intended to be a high-level replacement for the idiom of creating new threads to service a series of jobs. Along withExecutors, theCallableandFutureinterfaces are introduced, which expand uponRunnableto allow management, value return, and exception handling.- Low-level synchronization constructs
The
java.util.concurrent.lockspackage holds a set ...