@Asynchronous does not cause asynchronous EJB method call in JBossAS7

I'm struggling to figure out why the @Asynchronous method in my EJB is not actually being called asynchronously. I am working on JBoss AS 7 using CDI (with beans.xml) in a JSF2 project with simple .war packaging created by Maven.

EJB is packaged in .war along with managed JSF2 beans, which interacts with it. This is a simple @Stateless EJB. He used it by injecting it (via @Inject) into a JSF2-controlled bean that calls its @Asynchronous method.

Instead of calling the @Asynchronous method that returns the Future immediately, it runs synchronously, as if it were a regular direct call. This is true if I use a local view without an interface or a local business interface to invoke EJB.

Is @Asynchronous supported only for @Remote beans? If so, can it work inside a .war package, or do I need to pack an EJB jar in an EAR just to get this feature?

Simplified code, such as sake, with each class in the same package in .war:

public interface SomeEJB { public Future<Void> doSomething(); } @Stateless @Local(SomeEJB.class) public class SomeEJBImpl implements SomeEJB { @Asynchronous @Override public Future<Void> doSomething() { // Spend a while doing work // then: return new AsyncResult<Void>(null); } } @Named @RequestScoped public class JSFBean { @Inject private transient SomeEJB someEJB; private Future<Void> progress; // Called from JSF2, starts work and re-displays page public String startWorkAction() { // This call SHOULD return a Future immediately. Instead it blocks // until doWork() completes. progress = someEJB.doWork(); } public Boolean isDone() { return progress != null && progress.isDone(); } } 
+7
source share
1 answer

JBoss AS 7.0.2 does not support @Asynchronous by default. You must enable it. If it is not enabled, there are no warnings or error messages, asynchronous methods simply execute synchronously.

Yes, this one is user friendly.

To enable these features in this supposedly finished and released * product, you must run JBoss AS 7.0.2 using "standalone-preview.xml", for example:

 bin/standalone.sh --server-config=standalone-preview.xml 

or in AS 7.1 (beta) or later:

 bin/standalone.sh --server-config=standalone-full.xml 

... which receives the asynchronous methods that need to be called ... asynchronously.

  • (Admittedly, AS 7 does not require Java EE 6 Full Profile compliance, but a warning would be nice! Or some kind of documentation on known issues / holes! Everything but a silent, undocumented failure ...)

Update: as garcia-jj noted, removing lite=true from standalone.xml will also cause async EJB to work.

+9
source

All Articles