diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java index b22fff45..95c549dc 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java @@ -39,6 +39,7 @@ import java.util.*; public class InterceptorFactory { private static final Cache, Interceptor> interceptorCache = new MemoryCache<>(); private static final List globalInterceptorList = Collections.synchronizedList(new ArrayList<>()); + private static final Map> methodInterceptorListMap = new HashMap<>(); static { registerGlobalInterceptor(InnerGlobalInterceptor.class); @@ -59,15 +60,18 @@ public class InterceptorFactory { } public static List getListByTargetMethod(Method targetMethod) { - if (null == targetMethod) { - return null; - } + Assert.notNull(targetMethod, "目标方法不能为空!"); - List interceptors = new ArrayList<>(); - interceptors.addAll(globalInterceptorList); - addInterceptorByAnnotation(interceptors, targetMethod.getDeclaringClass().getAnnotation(Intercept.class)); - addInterceptorByAnnotation(interceptors, targetMethod.getAnnotation(Intercept.class)); - return interceptors; + return LockUtil.doubleCheckProcess(() -> !methodInterceptorListMap.containsKey(targetMethod), + targetMethod, + () -> { + List interceptors = new ArrayList<>(); + interceptors.addAll(globalInterceptorList); + addInterceptorByAnnotation(interceptors, targetMethod.getDeclaringClass().getAnnotation(Intercept.class)); + addInterceptorByAnnotation(interceptors, targetMethod.getAnnotation(Intercept.class)); + methodInterceptorListMap.put(targetMethod, interceptors); + }, + () -> methodInterceptorListMap.get(targetMethod)); } private static void addInterceptorByAnnotation(List interceptors, Intercept intercept) {