The thread title should be self-explnatory... I\'m a bit confused between the specification of below methos from AtomicBoolean class:
java.u
The documentation is pretty clear.
getAndSet --> "Atomically sets to the given value and returns the previous value."compareAndSet --> "Atomically sets the value to the given updated value if the current value == the expected value."Not surprisingly, compareAndSet takes two arguments.
In your specific case:
if (flag.getAndSet(false)) will set flag to false only if its previous value was trueif (flag.compareAndSet(true, false))