Java atomicstampedreference
AtomicStampedReference
is a class in Java's java.util.concurrent.atomic
package that provides atomic operations on a pair of reference and stamp values. It is used to manage objects that need to be updated atomically based on their version or stamp.
The AtomicStampedReference
class provides the following atomic operations:
getReference()
: Returns the current reference.getReference(int[] stampHolder)
: Returns the current reference and the current stamp.set(V newReference, int newStamp)
: Sets the reference and stamp to the specified new values.compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)
: Atomically sets the reference and stamp to the specified new values if the current reference and stamp equal the expected values, and returns true if the update was successful.attemptStamp(V expectedReference, int newStamp)
: Atomically sets the stamp to the specified new value if the current reference equals the expected value, and returns true if the update was successful.compareAndSet(int expectedStamp, int newStamp)
: Atomically sets the stamp to the specified new value if the current stamp equals the expected value, and returns true if the update was successful.
The stamp value is an integer that can be used to version objects or track modifications to them. It is updated atomically with the reference value. The AtomicStampedReference
class is useful for implementing lock-free data structures and algorithms that require high-performance concurrent access to objects with version or stamp values.