Class TransactionReaper


  • public class TransactionReaper
    extends java.lang.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)
    • 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​(java.lang.Object control)
      • getRemainingTimeoutMills

        public final long getRemainingTimeoutMills​(java.lang.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​(java.lang.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 - if true then the reaper will wait until all transactions have terminated (or been terminated by it). If false then the reaper will call setRollbackOnly on all the transactions.
      • isDynamic

        public static boolean isDynamic()
      • transactionLifetime

        public static long transactionLifetime()