-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapper method invocation should be non-blocking (work around JDK-8161372) #1929
Comments
That is a JDK's issue rather than MyBatis'. As MyBatis still supports Java 8, I thought about adding a preliminary check as you proposed, but it didn't make much difference (here is the JMH project that I used). [EDIT] |
@harawata |
You can verify the fix with 3.5.5-SNAPSHOT. |
…fAbsent() This is a workaround for JDK-8161372 mybatis#1929 https://groups.google.com/g/mybatis-user/c/iBTN98c0dP4/m/H6IJS-LzAQAJ We should drop this workaround once we drop Java 8 support or the fix is backported.
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
The text was updated successfully, but these errors were encountered: