diff --git a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java index 8ad2e49bd40..803e92b898a 100644 --- a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java +++ b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java @@ -512,6 +512,8 @@ public enum ContainerType { protected InterceptorManager interceptorManager; + private Set pendingInterceptors = new HashSet<>(); + // the order must be the same as CallbackType and getPre30LifecycleMethodNames private static final Class[] lifecycleCallbackAnnotationClasses = { AroundConstruct.class, @@ -3446,16 +3448,25 @@ protected String[] getPre30LifecycleMethodNames() { }; }; - private void initializeInterceptorManager() throws Exception { + private synchronized void initializeInterceptorManager() throws Exception { this.interceptorManager = new InterceptorManager(_logger, this, lifecycleCallbackAnnotationClasses, getPre30LifecycleMethodNames()); + if (!pendingInterceptors.isEmpty()) { + pendingInterceptors.forEach(this::registerSystemInterceptor); + pendingInterceptors.clear(); + } } - void registerSystemInterceptor(Object o) { - + void registerSystemInterceptor(Object interceptor) { if (needSystemInterceptorProxy()) { - interceptorManager.registerRuntimeInterceptor(o); + synchronized (this) { + if (interceptorManager == null) { + pendingInterceptors.add(interceptor); + } else { + interceptorManager.registerRuntimeInterceptor(interceptor); + } + } } }