Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous EJB 3.1 methods and Transactions

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

like image 509
anergy Avatar asked Oct 05 '11 10:10

anergy


People also ask

What is asynchronous method in Java?

An Asynchronous call does not block the program from the code execution. When the call returns from the event, the call returns back to the callback function. So in the context of Java, we have to Create a new thread and invoke the callback method inside that thread.

What are asynchronous business methods?

Asynchronous methods are typically used for long-running operations, for processor-intensive tasks, for background tasks, to increase application throughput, or to improve application response time if the method invocation result isn't required immediately.

Which annotation is required to mark a method asynchronous?

Annotation Type Asynchronous Used to mark a session bean method as an asynchronous method or to designate all business methods of a session bean class as asynchronous. An asychronous method must have return type void or Future<V> , where V is the result value type.

What is synchronous method invocation?

When a synchronous method is invoked, it completes executing before returning to the caller. An asynchronous method starts a job in the background and returns to the caller immediately. Synchronous Methods. A typical synchronous method returns the result directly to the caller as soon as it completes executing.


1 Answers

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

like image 159
stratwine Avatar answered Oct 24 '22 02:10

stratwine