AtomicStampedReference

Learn how the AtomicStampedReference class can be used to address the ABA problem that can manifest when classes manage their own memory.

If you are interviewing, consider buying our number#1 course for Java Multithreading Interviews.

Overview

Similar to the AtomicReference class, the AtomicStampedReference class contains a reference to an object and additionally an integer stamp. The integer stamp is usually incremented whenever the object pointed to by the reference is modified. The AtomicStampedReference class can be thought of as a generalization of the AtomicMarkableReference class, replacing the boolean with an integer. The integer stamp stored alongside the reference can also be used for other purposes such as maintaining one of the finite states a data structure can be in . The stamp and reference fields can be updated atomically, either together or individually.

The code widget below demonstrates the use of AtomicStampedReference and its common APIs.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy