7

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();
  }

}
casperOne
  • 73,706
  • 19
  • 184
  • 253
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • It's beginning to look like @Asynchronous isn't implemented in JBoss AS 7 (as of 7.0.2) - yet again, signs Java EE 6 implementations are still buggy and incomplete years after the spec's release. Sigh. It'd be nice to issue a warning or something not SILENTLY FAIL. – Craig Ringer Nov 03 '11 at 06:02
  • You can enable some off-by-default EJB3.1 features with the standalone-preview config in AS 7.0.2 . Invoke as: "bin/standalone.sh --server-config=standalone-preview.xml" – Craig Ringer Nov 03 '11 at 06:05

1 Answers1

9

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.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • Note that in AS 7.1 "standalone-preview.xml" is now "standalone-full.xml" – Craig Ringer Dec 13 '11 at 02:11
  • How to enable async EJB without using standalone-preview? Thank you. – Otávio Garcia Feb 12 '12 at 18:51
  • @garcia-jj It's now called standalone-full.xml in newer versions of JBoss AS 7, but the point is the same: You must run the server with a profile that supports asynchronous EJBs if you want to use asynchronous EJBs. If you don't like it, complain to JBoss, because that seems to be the only option you have right now. – Craig Ringer Feb 15 '12 at 02:19
  • 1
    I found other solution: remove attribute lite=true from urn:jboss:domain:ejb3:1.1 in standalone.xml. – Otávio Garcia Mar 05 '12 at 17:05
  • @garcia-jj How does the effect of that differ from using `standalone-full.xml` ? Any idea what features are active in standalone-full.xml that aren't activated by lite=false ? – Craig Ringer Mar 05 '12 at 23:39