Forum Stats

  • 3,816,536 Users
  • 2,259,202 Discussions
  • 7,893,507 Comments

Discussions

CDI event originator's EJB transaction waits for Observer(AFTER_SUCCESS) EJ

Hi!

I have the following scenario: (pesudo-code)


CallerObject.method() {
SessionBean1.method1(); // through remote bean interface
// [1]
}

@TransactionAttribute(REQUIRED)
SessionBean1.method1() {
// do something...
Event<myClass>.fire();
// do something...
}

ObserverObject.method2(@Observes(during=AFTER_SUCCESS) myClass) {
sessionBean2.method2(); // through local bean interface
}

@Asynchronous
@TransactionAttribute(REQUIRED)
SessionBean2.method2() {
// do something...
}

(with the usual container-managed transaction boundaries)


==> the following happens:

[1] is only reached AFTER the transaction in SessionBean2.method2() finishes! (Although the last statement in SessionBean1.method1() is reached way before that.)

It's as if SessionBean1.method1()'s transaction somehow isn't "released" (for want of a better word -- it does get committed immediately, before the event handler ObserverObject.method2() is called!) until the asynchronously called Session2.method2()'s transaction finishes as well.

Does anyone know how I could avoid that?


(The point of the whole setup would be to have the long-running SessionBean2.method2() run in the background after T1's completion and have SessionBean1.method1() return as soon as possible.)


P.S.: I have verified that
a) T1 is committed immediately (the records go in the DB)
b) SessionBean2.method2() is called asynchronously (control jumps to the next statement in the calling code immediately)
c) the SessionBean1.method1() doesn't return control to the caller code until T2 finishes



Thanks,
Agoston
This discussion has been closed.