When multiple threads read shared data, a change during a read can make the result unreliable. An immutable collection cannot be changed after creation, so readers can use it without a lock to guard against concurrent changes. section 7.7.6
Updates create a new structure and leave the original unchanged. For example, appending to list L1 creates a new list L2 with one additional element. A cache update can likewise return a new cache instance rather than changing the existing one. section 13.2.3 section 7.7.6
Immutability offers practical trade-offs:
- It can make code easier to reason about because other methods cannot change an object’s state. section 7.7.6
- It reduces shared state in parallel computations, but can make maintaining running state harder and updating large objects more expensive. section 7.7.6 section 13.2.3
- Concurrent writes can still race when two threads update the same shared cache; optimistic locking with versioning is one possible response. section 7.7.6























