Closed
Description
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;
]