2222import java .util .HashSet ;
2323import java .util .Map ;
2424import java .util .Set ;
25+ import java .util .concurrent .ConcurrentHashMap ;
26+ import java .util .concurrent .ConcurrentMap ;
2527
2628import org .apache .ibatis .reflection .ExceptionUtil ;
2729import org .apache .ibatis .util .MapUtil ;
@@ -34,6 +36,7 @@ public class Plugin implements InvocationHandler {
3436 private final Object target ;
3537 private final Interceptor interceptor ;
3638 private final Map <Class <?>, Set <Method >> signatureMap ;
39+ private final ConcurrentMap <Method , Boolean > methodMap = new ConcurrentHashMap <>();
3740
3841 private Plugin (Object target , Interceptor interceptor , Map <Class <?>, Set <Method >> signatureMap ) {
3942 this .target = target ;
@@ -53,9 +56,12 @@ public static Object wrap(Object target, Interceptor interceptor) {
5356
5457 @ Override
5558 public Object invoke (Object proxy , Method method , Object [] args ) throws Throwable {
56- try {
59+ boolean intercepted = MapUtil . computeIfAbsent ( methodMap , method , key -> {
5760 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 ) {
5965 return interceptor .intercept (new Invocation (target , method , args ));
6066 }
6167 return method .invoke (target , args );
0 commit comments