Skip to content

Commit

Permalink
[WFLY-12373] Cache injected objects in Jsr299Bindings[Create]Intercep…
Browse files Browse the repository at this point in the history
…tor to avoid contended gets from the Supplier
  • Loading branch information
bstansberry committed Aug 13, 2019
1 parent 336156b commit 27d5534
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Jsr299BindingsInterceptor implements org.jboss.invocation.Intercept
private final InterceptionType interceptionType;
private final ComponentInterceptorSupport interceptorSupport;
private final Supplier<InterceptorBindings> interceptorBindingsSupplier;
private volatile InterceptorBindings interceptorBindings;

private Jsr299BindingsInterceptor(final InterceptionType interceptionType, final ComponentInterceptorSupport interceptorSupport, final Supplier<InterceptorBindings> interceptorBindingsSupplier) {
this.interceptionType = interceptionType;
Expand Down Expand Up @@ -96,7 +97,11 @@ private Object doMethodInterception(InvocationContext invocationContext, Interce
public Object processInvocation(final InterceptorContext context) throws Exception {
final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
final InterceptorInstances interceptorInstances = interceptorSupport.getInterceptorInstances(componentInstance);
final InterceptorBindings interceptorBindings = interceptorBindingsSupplier.get();
InterceptorBindings interceptorBindings = this.interceptorBindings;
if (interceptorBindings == null) {
// Cache the bindings as reading the interceptorBindingsSupplier is contended
interceptorBindings = this.interceptorBindings = interceptorBindingsSupplier.get();
}
switch (interceptionType) {
case AROUND_INVOKE:
return doMethodInterception(context.getInvocationContext(), InterceptionType.AROUND_INVOKE, interceptorInstances, interceptorBindings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class Jsr299BindingsCreateInterceptor implements org.jboss.invocation.Int
private final String ejbName;
private final ComponentInterceptorSupport interceptorSupport;
private volatile BeanManagerImpl beanManager;
private volatile InterceptorBindings interceptorBindings;

public Jsr299BindingsCreateInterceptor(final Supplier<WeldBootstrapService> weldContainerSupplier,
final Supplier<InterceptorBindings> interceptorBindingsSupplier,
Expand Down Expand Up @@ -92,7 +93,11 @@ public Object processInvocation(InterceptorContext interceptorContext) throws Ex
bean = beanManager.getBean(descriptor);
}
}
InterceptorBindings interceptorBindings = interceptorBindingsSupplier.get();
InterceptorBindings interceptorBindings = this.interceptorBindings;
if (interceptorBindings == null) {
// Cache the bindings as reading the interceptorBindingsSupplier is contended
interceptorBindings = this.interceptorBindings = interceptorBindingsSupplier.get();
}

final ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
InterceptorInstances existing = interceptorSupport.getInterceptorInstances(componentInstance);
Expand Down

0 comments on commit 27d5534

Please sign in to comment.