Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 809
نمايش فراداده

Package java.util.concurrent.atomic

Java 5.0

This package includes classes that provide atomic operations on boolean, integer, and reference values. Instances of the classes defined here have the properties of volatile fields but also add atomic operations like the canonical compareAndSet( ), which verifies that the field holds an expected value, and, if it does, sets it to a new value. The classes also define a weakCompareAndSet( ) method that may be more efficient than compareAndSet( ) but may also fail to set the value even when the field holds the expected value.

The "Array" classes provide atomic access to arrays of values and provide volatile access semantics for array elements, which is not possible with the volatile modifier itself. The "FieldUpdater" classes use reflection to provide atomic operations on a named volatile field of an existing class. The AtomicMarkableReference class and AtomicStampedReference class maintain a reference value and an associated boolean or int value and allow the two values to be atomically manipulated together. These classes can be useful in concurrent algorithms that detect concurrent updates with version numbering, for example.

Most implementations of this package rely on low-level atomic instructions in the underlying CPU and perform atomic operations without the overhead of locking.

Classes

public class

AtomicBoolean implements Serializable; public class

AtomicInteger extends Number implements Serializable; public class

AtomicIntegerArray implements Serializable; public abstract class

AtomicIntegerFieldUpdater <T>; public class

AtomicLong extends Number implements Serializable; public class

AtomicLongArray implements Serializable; public abstract class

AtomicLongFieldUpdater <T>; public class

AtomicMarkableReference <V>; public class

AtomicReference <V> implements Serializable; public class

AtomicReferenceArray <E> implements Serializable; public abstract class

AtomicReferenceFieldUpdater <T, V>; public class

AtomicStampedReference <V>;