public final class TxnThreadLocal extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
TxnThreadLocal.Container |
Modifier and Type | Field and Description |
---|---|
static ThreadLocal<TxnThreadLocal.Container> |
threadlocal |
Modifier and Type | Method and Description |
---|---|
static void |
clearThreadLocalTxn()
Clears the threadlocal transaction.
|
static Txn |
getRequiredThreadLocalTxn()
Gets the threadlocal
Txn or throws a TxnMandatoryException if no transaction is found. |
static Txn |
getThreadLocalTxn()
Gets the threadlocal
Txn . |
static TxnThreadLocal.Container |
getThreadLocalTxnContainer()
ThreadLocalTransaction
Gets the ThreadLocal container that stores the Txn.
|
static void |
setThreadLocalTxn(Txn txn)
Sets the threadlocal transaction.
|
public static final ThreadLocal<TxnThreadLocal.Container> threadlocal
public static Txn getThreadLocalTxn()
Txn
. 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).
public static TxnThreadLocal.Container getThreadLocalTxnContainer()
public static Txn getRequiredThreadLocalTxn()
Txn
or throws a TxnMandatoryException
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).
TxnMandatoryException
- if no thread local transaction is found.public static void clearThreadLocalTxn()
If a transaction is available, it isn't aborted or committed.
public static void setThreadLocalTxn(Txn txn)
If a transaction is available, it isn't aborted or committed.
txn
- the new thread local transaction.Copyright © 2020. All rights reserved.