Class TxnThreadLocal
ThreadLocal
that contains the current Txn
. The Stm
and the Txn
should not rely on threadlocals, they are only used for convenience to reduce the need to carry around a
Txn.
This TxnThreadLocal has an optimization that prevents accessing the threadlocal too many times.
The Container wraps the Txn, so if a Thread gets a reference to that container and holds it, it
can modify the current transaction with a direct field access instead of another threadlocal access. It should
be used with extreme care, because the Container should not leak to another thread. It is very useful for the
TxnExecutor
for example because a get/getAndSet/clear needs to be called otherwise.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clears the threadlocal transaction.static Txn
Gets the threadlocalTxn
or throws aTxnMandatoryException
if no transaction is found.static Txn
Gets the threadlocalTxn
.static TxnThreadLocal.Container
ThreadLocalTransaction Gets the ThreadLocal container that stores the Txn.static void
setThreadLocalTxn
(Txn txn) Sets the threadlocal transaction.
-
Field Details
-
threadlocal
-
-
Constructor Details
-
TxnThreadLocal
private TxnThreadLocal()
-
-
Method Details
-
getThreadLocalTxn
Gets the threadlocalTxn
. If no transaction is set, null is returned.No checks are done on the state of the transaction (so it could be that an aborted or committed transaction is returned).
- Returns:
- the threadlocal transaction.
-
getThreadLocalTxnContainer
ThreadLocalTransaction Gets the ThreadLocal container that stores the Txn. Use this with extreme care because the Container should not leak to another thread. It is purely means as a performance optimization to prevent repeated (expensive) threadlocal access, and replace it by a cheap field access.- Returns:
- the Container. The returned value will never be null.
-
getRequiredThreadLocalTxn
Gets the threadlocalTxn
or throws aTxnMandatoryException
if no transaction is found.No checks are done on the state of the transaction (so it could be that an aborted or committed transaction is returned).
- Returns:
- the threadlocal transaction.
- Throws:
TxnMandatoryException
- if no thread local transaction is found.
-
clearThreadLocalTxn
public static void clearThreadLocalTxn()Clears the threadlocal transaction.If a transaction is available, it isn't aborted or committed.
-
setThreadLocalTxn
Sets the threadlocal transaction. The transaction is allowed to be null, effectively clearing the current thread local transaction.If a transaction is available, it isn't aborted or committed.
- Parameters:
txn
- the new thread local transaction.
-