The Session Bean Component Contract of the Enterprise JavaBeans 3.1 Specification (JSR 318 Proposed Final Draft) introduces the possibility of exposing methods of session beans with asynchronous semantics.
What does that mean?
For asynchronous invocations, control returns to the client before the container dispatches the invocation to a bean instance.
When a client invokes an asynchronous method, the container returns control to the client immediately and continues processing the invocation on a separate thread.
How to expose session bean’s methods asynchronously
This annotation can be applied to
- a business method of a bean class
- a method of a
- the class level of a bean class (or super class)
- the class level of a particular
Local/Remotebusiness interface (or super interface)
Application to a class level causes that all methods declared on that class or interface are asynchronous.
Alternatively, asynchronous methods can be designated via the deployment descriptor.
What does an asynchronous method look like?
The return type of an asynchronous method is either void or
V is the result value type.
||must not declare any application exceptions|
The Client View
When invoking an asynchronous method the client should expect to receive a system exception (
The system exception will be thrown by the container if it has problems to allocate the internal resources required to support the asynchronous method. The client may retry the asynchronous method invocation at a later time.
Any application exception resulting from the method execution will be available via the
Interpretation of the Future<V> object
An EJB Container Provider is permitted to define a timeout value that governs the maximum amount of time the container maintains result values for completed asynchronous invocations. However, the configuration of this timeout is vendor-specific.
From the session bean’s view there is never a transaction context flowing in from the client to asynchronously invoked methods.
Example: The semantics of the
REQUIRED transaction attribute on an asynchronous method are exactly the same as