I am going through book Java concurrency in practice
I came across the statement for volatile should be used in following criteria
- Writes to the variable do not depend on its current value, or you can ensure that only a single thread ever updates/writes the value.
- The variable does not participate in invariants with other state variables
- Locking is not required for any other reason while the variable is being accessed.
Can anyone explain me these three scenerios with example.