Concurrent Data Structures
Java 5 introduced several high-level
data structures in the
java.util.concurrent
package. CopyOnWriteArrayList
is a thread-safe alternative to ArrayList that copies the underlying array
during modifications. ConcurrentHashMap
is a thread-safe alternative
to HashMap that only incurs a synchronization penalty on segments of the map
that were modified. The BlockingQueue was introduced to allow producers
to block
and wait while a queue is full, and allow consumers to block and wait
while a queue is empty.
The Executor Framework
The executor framework provides a layer of abstraction
over multithreaded task
execution. The ExecutorService manages a thread pool that accepts
Runnable
or Callable tasks. Submitting a task immediately returns
a
Future object, which contains methods that return the status and result
of a running task. The executor framework effectively decouples tasks from their
execution policies.