Core concept

volatile boolean stopped = false;
// visible to other threads immediately
Advertisement

How it works

Doesn't prevent compound ops races. Use AtomicX for that.

Advertisement

Trade-offs + gotchas

Simple flags. Double-checked locking.