@Documented @Inherited @Retention(value=RUNTIME) @Target(value=METHOD) public @interface Asynchronous
The default behavior is to execute a Managed object method synchronously within the calling transaction. When annotated as @Asynchronous, a method runs asynchronously in a separate transaction. A new transaction is transparently started for the method, and deadlocks are automatically retried.
If the work done in an asynchronous method is supposed to be rolled
back, the method should throw a Transaction.Rollback
exception.
A method annotated as @Asynchronous must have a void return and parameters are restricted to those types supported for Managed objects.
The Transaction.Result
of an asynchronous
method is not available to an application. Applications that need to
keep track of this need to implement a separate non-transactional
mechanism to track this.
Execution of asynchronous methods have the following behavior:
@Managed class MyClass { @Asynchronous void asyncOp(int val); } new Transaction() { @Override public void run() { ... myObj.asyncOp(1); myObj.asyncOp(2); } }.execute();The runtime insures that asyncOp() is called with val==1 first. Execution of asynchronous methods on different instances have no order guarantees.
It is important to note that execution of an asynchronous method and its associated transaction only happen after the calling transaction commits, it is not executed if the calling transaction is rolled back for any reason.
If the @Asynchronous annotation is used on a method for a class that isn't @Managed, the annotation is ignored.
Managed
,
Transaction
,
Transaction.Rollback
Modifier and Type | Optional Element and Description |
---|---|
Transaction.IsolationLevel |
isolationLevel
Define the transaction isolation level used when running
this transaction.
|
public abstract Transaction.IsolationLevel isolationLevel