6

I wrote a small test to understand asynchronized behavior in EJB3.1 using @Asynchronous annotation. It seems that:

If the method exist in the same bean as the caller,

  1. Call is no longer asynchronized.
  2. The caller transaction is marked for roll back, if the transaction in the asynchronous method is rolled back; its probably the side effect of 1.

However, if the asynchronous method exists in another bean, the behavior is expected i.e. call is asynchronous and the caller transaction is independent (async method have REQUIRES_NEW behavior for transaction). This is puzzling for me, as why the behavior is not the same in both cases. Would someone please clarify?

P.S. Environment EJB 3.1, JBoss 6

anergy
  • 1,374
  • 2
  • 13
  • 29
  • 1
    are you calling the method using `SessionContext#getBusinessObject(class)` instead of using `this` keyword ? (the difference is explained [here](http://stackoverflow.com/questions/3381002/how-is-the-return-value-of-sessioncontext-getbusinessobject-different-from-thi/3384128#3384128) ) – stratwine Oct 05 '11 at 23:11
  • @stratwine Almost certainly the problem, I would just convert it to an answer. – Brett Kail Oct 07 '11 at 13:09
  • @stratwine You are right, please write your comments in answer so I can accept – anergy Oct 07 '11 at 15:47

1 Answers1

5

Calling the method using this keyword instead of using SessionContext#getBusinessObject(class) causes that. (the difference is explained here )

Community
  • 1
  • 1
stratwine
  • 3,663
  • 2
  • 26
  • 32