Problem Statement
Which practice improves thread-safety for shared caches inside a process?
Explanation
Concurrent structures need clear ownership and atomicity. Use read–write locks or CAS-based maps. Keep critical sections short and avoid holding locks during I/O.
Prefer immutable snapshots for readers when feasible; it reduces contention.
Code Solution
SolutionRead Only
ConcurrentMap<K,V> cache; // atomics for putIfAbsent/get
Practice Sets
This question appears in the following practice sets:
