Package java.util.concurrent | | 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 are executor implementations based on highly configurable thread pools. The Executors class provides convenient factory methods for obtaining instances of these thread pool implementations. -
- Synchronizers
-
A number of classes in this package are useful for synchronizing two or more concurrent threads. See CountDownLatch , CyclicBarrier , Exchanger , and Semaphore . Interfaces public interface BlockingQueue <E> extends java.util.Queue<E>; public interface Callable <V>; public interface CompletionService <V>; public interface ConcurrentMap <K, V> extends java.util.Map<K, V>; public interface Delayed extends Comparable<Delayed>; public interface Executor ; public interface ExecutorService extends Executor; public interface Future <V>; public interface RejectedExecutionHandler ; public interface ScheduledExecutorService extends ExecutorService; public interface ScheduledFuture <V> extends Delayed, Future<V>; public interface ThreadFactory ; Enumerated Types public enum TimeUnit ; Collections public class ArrayBlockingQueue <E> extends java.util.AbstractQueue<E> implements BlockingQueue<E>, Serializable; public class ConcurrentHashMap <K, V> extends java.util.AbstractMap<K, V> implements ConcurrentMap<K, V> Serializable; public class ConcurrentLinkedQueue <E> extends java.util.AbstractQueue<E> implements java.util.Queue<E>, Serializable; public class CopyOnWriteArrayList <E> implements java.util.List<E>, java.util.RandomAccess, Cloneable, Serializable; public class CopyOnWriteArraySet <E> extends java.util.AbstractSet<E> implements Serializable; public class DelayQueue <E extends Delayed> extends java.util.AbstractQueue<E> implements BlockingQueue<E>; public class LinkedBlockingQueue <E> extends java.util.AbstractQueue<E> implements BlockingQueue<E>, Serializable; public class PriorityBlockingQueue <E> extends java.util.AbstractQueue<E> implements BlockingQueue<E>, Serializable; public class SynchronousQueue <E> extends java.util.AbstractQueue<E> implements BlockingQueue<E>, Serializable; Other Classes public abstract class AbstractExecutorService implements ExecutorService; public class ThreadPoolExecutor extends AbstractExecutorService; public class ScheduledThreadPoolExecutor extends ThreadPoolExecutor implements ScheduledExecutorService; public class CountDownLatch ; public class CyclicBarrier ; public class Exchanger <V>; public class ExecutorCompletionService <V> implements CompletionService<V>; public class Executors ; public class FutureTask <V> implements Future<V>, Runnable; public class Semaphore implements Serializable; public static class ThreadPoolExecutor.AbortPolicy implements RejectedExecutionHandler; public static class ThreadPoolExecutor.CallerRunsPolicy implements RejectedExecutionHandler; public static class ThreadPoolExecutor.DiscardOldestPolicy implements RejectedExecutionHandler; public static class ThreadPoolExecutor.DiscardPolicy implements RejectedExecutionHandler; Exceptions public class BrokenBarrierException extends Exception; public class CancellationException extends IllegalStateException; public class ExecutionException extends Exception; public class RejectedExecutionException extends RuntimeException; public class TimeoutException extends Exception; |