Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Asynchronous not resulting in async invocation of EJB method in JBossAS7

I'm struggling to figure out why an @Asynchronous method in my EJB isn't actually being invoked asynchronously. I'm running on JBoss AS 7 using CDI (with beans.xml) in a JSF2 project with simple .war packaging produced by Maven.

The EJB is packaged in a .war along with the JSF2 managed beans that interact with it. It's a simple @Stateless EJB. It's used by injecting it (via @Inject) into a JSF2 managed bean that invokes its @Asynchronous method.

Instead of the @Asynchronous method invocation returning a Future immediately, it executes synchronously as if it were an ordinary unproxied direct call. This is true whether I use a local no-interface view or a local business interface to invoke the EJB.

Is @Asynchronous only supported for @Remote beans? If so, can it work within .war packaging or do I have to package an EJB jar in an EAR just to get this one feature?

Simplified code for example's sake, with each class in the same package in a .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();
  }

}
like image 812
Craig Ringer Avatar asked Nov 03 '11 05:11

Craig Ringer


1 Answers

JBoss AS 7.0.2 doesn't support @Asynchronous by default. You have to turn it on. If it's not turned on there's no warning or error message, asynchronous methods are just executed synchronously.

Yep, that's user friendly.

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

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 gets the asynchronous methods to be invoked ... asynchronously.

  • (Admittedly AS 7 doesn't claim Java EE 6 Full Profile compliance, but a warning would be nice! Or some documentation on the known issues/holes! Anything but silent undocumented failure...)

Update: As noted by garcia-jj, removing lite=true from standalone.xml will also get async EJBs working.

like image 123
Craig Ringer Avatar answered Oct 15 '22 01:10

Craig Ringer