![]() | Concurrency Utilities |
Using the Concurrency Utilities, instead of developing components such asthread pools yourself, offers a number of advantages:
synchronized,volatile,wait(),notify(), andnotifyAll()) are difficult to use correctly, and errors using these facilities can be difficult to detect and debug. By using standardized, extensively tested concurrency building blocks, many potential sources of threading hazards such as deadlock, starvation, race conditions, or excessive context switching are eliminated. The concurrency utilities have been carefully audited for deadlock, starvation, and race conditions.In short, using the Concurrency Utilities to implement a concurrentapplication can help you make your program clearer, shorter, faster, morereliable, more scalable, easier to write, easier to read, and easier tomaintain.
The Concurrency Utilities includes:
Executor framework is a framework for standardizing invocation, scheduling, execution, and control of asynchronous tasks according to a set of execution policies. Implementations are provided that allow tasks to be executed within the submitting thread, in asingle background thread (as with events in Swing), in a newly created thread, or in athread pool, and developers can create of Executor supporting arbitrary execution policies. The built-in implementations offer configurable policies such as queue length limits andsaturation policy which can improve the stability of applications by preventing runaway resource consumption.Queue andBlockingQueue interfaces, and high-performance, concurrent implementations ofMap,List, andQueue.java.util.concurrent.atomic offer higher performance than would be available by using synchronization (on most platforms), making them useful for implementing high-performance concurrent algorithms as well as conveniently implementing counters and sequence number generators.java.util.concurrent.locks package provides a high-performance lock implementation with the same memory semantics as synchronization, but which also supports specifying a timeout when attempting to acquire a lock, multiple condition variables per lock, non-lexically scoped locks, and support for interrupting threads which are waiting to acquire a lock.System.nanoTime method enables access to a nanosecond-granularity time source for making relative time measurements, and methods which accept timeouts (such as theBlockingQueue.offer,BlockingQueue.poll,Lock.tryLock,Condition.await, andThread.sleep) can take timeout values in nanoseconds. The actual precision ofSystem.nanoTime is platform-dependent.![]() |