Name

Package java.util.concurrent

Synopsis

This package includes a number of powerful utilities for multithreaded programming. Most of these utilities fall into three main categories:

Collections

This package extends the Java Collections Framework, adding the threadsafe classes ConcurrentHashMap, CopyOnWriteArrayList, CopyOnWriteArraySet, and ConcurrentLinkedQueue. These classes achieve threadsafety without relying exclusively on synchronized methods, greatly increasing the number of threads that can safely use them concurrently. ConcurrentHashMap implements the ConcurrentMap interface, which adds important atomic methods to the base java.util.Map interface.

In addition to these Map, List, Set, and Queue implementations, this package also defines the BlockingQueue interface. Blocking queues are important in many concurrent algorithms, and this package provides a variety of useful implementations: ArrayBlockingQueue, DelayQueue, LinkedBlockingQueue, PriorityBlockingQueue, and SynchronousQueue.

Asynchronous Execution with Thread Pools

java.util.concurrent provides a robust framework for asynchronous execution of tasks defined by the existing java.lang.Runnable interface or the new Callable interface. The Executor, ExecutorService, and ScheduledExecutorService interfaces define methods for executing (or scheduling for future execution) Runnable and Callable tasks. The Future interface represents the future result of the asynchronous execution of a task. ThreadPoolExecutor and ScheduledThreadPoolExecutor ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.