The thread title should be self-explnatory... I\'m a bit confused between the specification of below methos from AtomicBoolean
class:
java.u
The thread is a bit old but nobody mentioned that getAndSet will be more efficient than compareAndSet. CAS is a very costly instruction (on all CPU architectures, so JVM does not matter here). So they are not really equivalent.
So regarding the OP, both methods produce the same behaviour but it will not have the same performance, use getAndSet when you can.