DATAKV-297 - Use computeIfAbsent to create keyspace maps.

We now use computeIfAbsent to ensure atomic creation of keyspace maps if the underlying Map implementation allows for concurrent access.
This commit is contained in:
Mark Paluch
2020-09-30 14:52:55 +02:00
parent e8cdd00ff1
commit d1929fa546

View File

@@ -189,17 +189,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
Assert.notNull(keyspace, "Collection must not be null for lookup.");
Map<Object, Object> map = store.get(keyspace);
if (map != null) {
return map;
}
addMapForKeySpace(keyspace);
return store.get(keyspace);
return store.computeIfAbsent(keyspace, it -> CollectionFactory.createMap(keySpaceMapType, 1000));
}
private void addMapForKeySpace(String keyspace) {
store.put(keyspace, CollectionFactory.createMap(keySpaceMapType, 1000));
}
}