public class TransactionalCallable<T>
extends java.lang.Object
implements java.util.concurrent.Callable<T>
Runaway threads that are executing a TransctionalCallable object are those that are still running even after the owner thread ends the transaction. Such runaway threads will silently fail when they attempt to access transactional data since the transaction is no longer active. Therefore it is up to the owner thread to wait for the completion of any threads that it has scheduled.
The callable object inherits thread local values (such as the current session name) from the owner thread during the call to the constructor
An owner thread can spawn as many threads as it wishes
An example is shown below:
class MyCallable extends TransactionalCallable { ... protected Object _call() throws Exception { ... perform work ... } } ExecutorService executorService = Executors.newFixedThreadPool(10); TransactionalCallable work1 = ... TransactionalCallable work2 = ... // submit two TransactionalCallable in parallel. Future future1 = executorService.submit(work1); Future future2 = executorService.submit(work2); ... owner thread performs other work // wait for parallel work to finish future1.get(); future2.get();
Modifier | Constructor and Description |
---|---|
protected |
TransactionalCallable()
Constructor for subclassing.
|
|
TransactionalCallable(java.util.concurrent.Callable<T> callable)
Constructor for wrapping a callable object so that it can be executed asynchronously in a transaction
|
Modifier and Type | Method and Description |
---|---|
protected T |
_call()
Implementations of this method can perform only read-only access to transactional data structures
|
T |
call() |
Transaction |
getOwner()
Returns the transaction that owns this callable object.
|
protected TransactionalCallable()
_call()
methodpublic TransactionalCallable(java.util.concurrent.Callable<T> callable)
callable
- the callable object to be calledpublic Transaction getOwner()
public final T call() throws java.lang.Exception
call
in interface java.util.concurrent.Callable<T>
java.lang.Exception
protected T _call() throws java.lang.Exception
java.lang.Exception