Since the map does not update when used, use HashMapthat gives excellent O (1) search performance (with sacrificing thread safety).
When the time comes for an update, create a new map and replace the links.
Think of using AtomicReferenceto make the swap stream safe:
private final AtomicReference<Map<K, V>> mapRef = new AtomicReference<>();
For use:
mapRef.get().get(key);
To initialize or replace a new card:
Map<K, V> newMap = new HashMap<>();
mapRef.set(newMap);
source
share