Skip to content

Locking overhead on Java 8 caused by ConcurrentHashMap.computeIfAbsent(…) [DATACMNS-1396] #1831

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: pull request #319

Backported to: 2.1.1 (Lovelace SR1), 2.0.11 (Kay SR11)

Metadata

Metadata

Assignees

Labels

in: mappingMapping and conversion infrastructuretype: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions