Java.util.concurrent.atomic.AtomicReference is a class designed to update variables in a thread-safe way. Why do we need the class AtomicReference
? Why can we not simply use a volatile variable? And how can we use it correctly?
Why AtomicReference?
For the tool I am writing, I need to detect if an object was called from multiple threads. I use the following immutable class for this: