Class TransactionReaper
- java.lang.Object
-
- com.arjuna.ats.arjuna.coordinator.TransactionReaper
-
public class TransactionReaper extends Object
Class to record transactions with non-zero timeout values, and class to implement a transaction reaper thread which terminates these transactions once their timeout elapses.- Since:
- JTS 1.0.
- Version:
- $Id: TransactionReaper.java 2342 2006-03-30 13:06:17Z $
- Author:
- Mark Little (mark@arjuna.com)
-
-
Field Summary
Fields Modifier and Type Field Description static longdefaultCancelFailWaitPeriodstatic longdefaultCancelWaitPeriodstatic longdefaultCheckPeriodstatic longdefaultTracePeriodstatic longdefaultUntracedPeriodstatic intdefaultZombieMaxstatic StringDYNAMICstatic StringNORMALstatic StringPERIODIC
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(ReaperMonitor listener)voidcheck()process all entries in the timeout queue which have expired.longcheckingPeriod()voiddoWork()longgetRemainingTimeoutMills(Object control)Given the transaction instance, this will return the time left before the transaction is automatically rolled back if it has not been terminated.intgetTimeout(Object control)Given a Control, return the associated timeout, or 0 if we do not know about it.voidinsert(Reapable control, int timeout)timeout is given in seconds, but we work in milliseconds.static voidinstantiate()Currently we let the reaper thread run at same priority as other threads.static booleanisDynamic()longnumberOfTimeouts()Return the number of timeouts registered.longnumberOfTransactions()voidremove(Object control)booleanremoveListener(ReaperMonitor listener)static voidterminate(boolean waitForTransactions)Terminate the transaction reaper.static longtransactionLifetime()static TransactionReapertransactionReaper()Starting with 4.8, this method will always return an instance, will never return null.voidwaitForWork()
-
-
-
Field Detail
-
NORMAL
public static final String NORMAL
- See Also:
- Constant Field Values
-
DYNAMIC
public static final String DYNAMIC
- See Also:
- Constant Field Values
-
PERIODIC
public static final String PERIODIC
- See Also:
- Constant Field Values
-
defaultCheckPeriod
public static final long defaultCheckPeriod
- See Also:
- Constant Field Values
-
defaultCancelWaitPeriod
public static final long defaultCancelWaitPeriod
- See Also:
- Constant Field Values
-
defaultCancelFailWaitPeriod
public static final long defaultCancelFailWaitPeriod
- See Also:
- Constant Field Values
-
defaultUntracedPeriod
public static final long defaultUntracedPeriod
- See Also:
- Constant Field Values
-
defaultTracePeriod
public static final long defaultTracePeriod
- See Also:
- Constant Field Values
-
defaultZombieMax
public static final int defaultZombieMax
- See Also:
- Constant Field Values
-
-
Method Detail
-
checkingPeriod
public final long checkingPeriod()
-
check
public final void check()
process all entries in the timeout queue which have expired. entries for newly expired transactions are passed to a worker thread for cancellation and requeued for subsequent progress checks. the worker is given a kick if such checks find it is wedged. Timeout is given in milliseconds. Runs on the ReaperThread
-
waitForWork
public final void waitForWork()
-
doWork
public final void doWork()
-
numberOfTransactions
public final long numberOfTransactions()
- Returns:
- the number of items in the reaper's list.
- Since:
- JTS 2.2. Note: this is a) expensive and b) an approximation. Should be called only by test code.
-
numberOfTimeouts
public final long numberOfTimeouts()
Return the number of timeouts registered. Note: this is a) expensive and b) an approximation. Should be called only by test code.- Returns:
- The number of timeouts registered.
-
addListener
public final void addListener(ReaperMonitor listener)
-
removeListener
public final boolean removeListener(ReaperMonitor listener)
-
insert
public final void insert(Reapable control, int timeout)
timeout is given in seconds, but we work in milliseconds. Attempting to insert an element that is already present is an error (IllegalStateException)
-
remove
public final void remove(Object control)
-
getRemainingTimeoutMills
public final long getRemainingTimeoutMills(Object control)
Given the transaction instance, this will return the time left before the transaction is automatically rolled back if it has not been terminated.- Parameters:
control-- Returns:
- the remaining time in milliseconds.
-
getTimeout
public final int getTimeout(Object control)
Given a Control, return the associated timeout, or 0 if we do not know about it. Return in seconds! Takes an Object because TransactionFactoryImple.getTransactionInfo and ArjunaTransactionImple.propagationContext use it and don't have a Reapable.
-
instantiate
public static void instantiate()
Currently we let the reaper thread run at same priority as other threads. Could get priority from environment.
-
transactionReaper
public static TransactionReaper transactionReaper()
Starting with 4.8, this method will always return an instance, will never return null. This causes the reaper to be instantiated unnecessarily in some cases, but that's cheaper than the alternatives.- Returns:
- a TransactionReaper singleton.
-
terminate
public static void terminate(boolean waitForTransactions)
Terminate the transaction reaper. This is a synchronous operation and will only return once the reaper has been shutdown cleanly. Note, this method assumes that the transaction system has been shutdown already so no new transactions can be created, or we could be here for a long time!- Parameters:
waitForTransactions- iftruethen the reaper will wait until all transactions have terminated (or been terminated by it). Iffalsethen the reaper will call setRollbackOnly on all the transactions.
-
isDynamic
public static boolean isDynamic()
-
transactionLifetime
public static long transactionLifetime()
-
-