In a book on programming I read:
For “infinite” loops, there should be some way to tell the thread that it is no longer needed, such as via an AtomicBoolean flag
What if instead of AtomicBoolean
it had had volatile boolean
? What negative efects are eliminated by having AtomicBoolean
as opposed to volatile boolean
for the case above?
If we use the variable exclusively as a flag for thread termination, is there still a difference between AtomicBoolean
and volatile
boolean
?