Description
Akshay Gehi opened DATACMNS-1396 and commented
ConcurrentHashMap.computeIfAbsent(k,f) locks bin when k present - this is documented in the following bug report https://bugs.openjdk.java.net/browse/JDK-8161372
Classes such as the ones mentioned below make use of computeIfAbsent without considering the impact of the above JDK issue. This causes a bottleneck while processing large MongoDB documents with complex arrays in them. This issue may be seen in other scenarios too because its fairly generic
Classes and methods affected:
CustomConversions$ConversionTargetsCache.computeIfAbsent
DefaultTypeMapper.getFromCacheOrCreate
Proposed fix:
Call get before calling computeIfAbsent
V value = map.get(key);
if (value == null) {
value = map.computeIfAbsent(key, function);
}
return value;
Affects: 2.0.10 (Kay SR10), 2.1 GA (Lovelace)
Attachments:
- Spring Data - Compute If Absent.png (192.14 kB)
Referenced from: pull request #319
Backported to: 2.1.1 (Lovelace SR1), 2.0.11 (Kay SR11)