Search code examples
jakarta-eeasynchronousmanaged-beanview-scope

Is there a way to use @Asynchronous methods in a @ManagedBean @ViewScoped?


I have a ManagedBean Class that will have load method, this load method would then call 2 @Asynchronous methods inside that class.

@ManagedBean
@ViewScoped
public class Loader implements Serializable {
private static final long serialVersionUID = 1L;

   public void load{
      loadMethodOne();
      loadMethodTwo();
   }

   @Asynchronous
   public void loadMethodOne(){
   ...
   }

   @Asynchronous
   public void loadMethodTwo(){
   ...
   }
}

This do not work, but calling an EJB class with 2 @Asynchronous methods works well.

@ManagedBean
@ViewScoped
public class Loader implements Serializable {
private static final long serialVersionUID = 1L;

   @EJB
   private AsyncLoader loader;

   public void load{
      loader.loadMethodOne();
      loader.loadMethodTwo();
   }
}

Is there a way to make it work inside the ManagedBean class?


Solution

  • @Asynchronous is not part of JSF and it will not work on beans annotated as @ManagedBean because it's JSF that instantiate those beans.