Skip to content

Mapper method invocation should be non-blocking (work around JDK-8161372) #1929

Closed
@lixinwen

Description

@lixinwen

MyBatis version

3.5.4

Database vendor and version

Test case or example project

MapperProxy#cachedInvoker {methodCache.computeIfAbsent}
In ConcurrentHashMap#computeIfAbsent, the following code will cause lock acquire:
[
else if ((fh = f.hash) == MOVED)
tab = helpTransfer(tab, f);
else {
boolean added = false;
// Here, even if the method and corresponding MapperMethodInvoker already exist
synchronized (f) {
]
I think, for mybatis, this lock is not necessary, maybe should change the code like follow:
[
MapperMethodInvoker invoker = methodCache.get(method);
if (invoker == null) {
MapperMethodInvoker newInvoker = .......
MapperMethodInvoker old = methodCache.putIfAbsent(newInvoker);
if (old != null) {
invoker = old;
}
}
return invoker;
]

Steps to reproduce

Expected result

Actual result

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions