EJB Asynchronous method Interceptors : is it possible to execute interceptor method in the caller thread

429 views Asked by At

If a method annotated with @Asynchronous, has an interceptor, the @AroundInvoke method gets executed in the same thread that will execute the asynchronous method, is it possible to make the execution of the interceptor method happens in the thread that made the call to the async method?

This is to propagate data from caller thread to the thread that will execute the async method

bellow a code snippet I used to test this :

@Stateless
public class ServiceA{
  @Asynchronous
  @Interceptors(ServiceAInterceptor.class)
  public void m1(){ ... }
}

public class ServiceAInterceptor{
  @AroundInvoke
  public Object intercept(InvocationContext context) throws Exception {
    ...
    return context.proceed();
  }
}

@Stateless
public class ServiceB{
  public void m2(){
    serviceA.m1();
  }
}

Even if @Interceptors is moved to the class level, the behavior will be the same.
Thanks for any help

0

There are 0 answers