22
22
import java .util .HashSet ;
23
23
import java .util .Map ;
24
24
import java .util .Set ;
25
+ import java .util .concurrent .ConcurrentHashMap ;
26
+ import java .util .concurrent .ConcurrentMap ;
25
27
26
28
import org .apache .ibatis .reflection .ExceptionUtil ;
27
29
import org .apache .ibatis .util .MapUtil ;
@@ -34,6 +36,7 @@ public class Plugin implements InvocationHandler {
34
36
private final Object target ;
35
37
private final Interceptor interceptor ;
36
38
private final Map <Class <?>, Set <Method >> signatureMap ;
39
+ private final ConcurrentMap <Method , Boolean > methodMap = new ConcurrentHashMap <>();
37
40
38
41
private Plugin (Object target , Interceptor interceptor , Map <Class <?>, Set <Method >> signatureMap ) {
39
42
this .target = target ;
@@ -53,9 +56,12 @@ public static Object wrap(Object target, Interceptor interceptor) {
53
56
54
57
@ Override
55
58
public Object invoke (Object proxy , Method method , Object [] args ) throws Throwable {
56
- try {
59
+ boolean intercepted = MapUtil . computeIfAbsent ( methodMap , method , key -> {
57
60
Set <Method > methods = signatureMap .get (method .getDeclaringClass ());
58
- if (methods != null && methods .contains (method )) {
61
+ return methods != null && methods .contains (method );
62
+ });
63
+ try {
64
+ if (intercepted ) {
59
65
return interceptor .intercept (new Invocation (target , method , args ));
60
66
}
61
67
return method .invoke (target , args );
0 commit comments