jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r550752 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
Date Tue, 26 Jun 2007 09:34:13 GMT
Author: mreutegg
Date: Tue Jun 26 02:34:12 2007
New Revision: 550752

URL: http://svn.apache.org/viewvc?view=rev&rev=550752
Log:
JCR-982: Each TransactionContext creates new thread

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?view=diff&rev=550752&r1=550751&r2=550752
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
Tue Jun 26 02:34:12 2007
@@ -18,6 +18,7 @@
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.util.Timer;
 
 import javax.transaction.xa.XAException;
 import javax.transaction.Status;
@@ -27,12 +28,12 @@
 /**
  * Represents the transaction on behalf of the component that wants to
  * explictely demarcate transcation boundaries. After having been prepared,
- * starts a thread that rolls back the transaction if some time passes without
+ * schedules a task that rolls back the transaction if some time passes without
  * any further action. This will guarantee that global objects locked by one
  * of the resources' {@link InternalXAResource#prepare} method, are eventually
  * unlocked.
  */
-public class TransactionContext implements Runnable {
+public class TransactionContext extends Timer.Task {
 
     /**
      * Logger instance.
@@ -40,6 +41,11 @@
     private static final Logger log = LoggerFactory.getLogger(TransactionContext.class);
 
     /**
+     * Create a global timer for all transaction contexts.
+     */
+    private static final Timer TIMER = new Timer(true);
+
+    /**
      * Transactional resources.
      */
     private final InternalXAResource[] resources;
@@ -140,8 +146,8 @@
             throw e;
         }
 
-        // start rollback thread in case the commit is never issued
-        new Thread(this, "RollbackThread").start();
+        // start rollback task in case the commit is never issued
+        TIMER.schedule(this, timeout * 1000, Integer.MAX_VALUE);
     }
 
     /**
@@ -178,6 +184,9 @@
         afterOperation();
         status = Status.STATUS_COMMITTED;
 
+        // cancel the rollback task
+        cancel();
+
         if (txe != null) {
             XAException e = new XAException(XAException.XA_RBOTHER);
             e.initCause(txe);
@@ -210,25 +219,19 @@
         afterOperation();
         status = Status.STATUS_ROLLEDBACK;
 
+        // cancel the rollback task
+        cancel();
+
         if (errors != 0) {
             throw new XAException(XAException.XA_RBOTHER);
         }
     }
 
     /**
-     * {@inheritDoc}
-     * <p/>
-     * Waits for the amount of time specified as transaction timeout. After
-     * this time has elapsed, rolls back the transaction if still prepared
-     * and marks the transaction rolled back.
+     * Rolls back the transaction if still prepared and marks the transaction
+     * rolled back.
      */
     public void run() {
-        try {
-            Thread.sleep(timeout * 1000);
-        } catch (InterruptedException e) {
-            /* ignore */
-        }
-
         synchronized (this) {
             if (status == Status.STATUS_PREPARED) {
                 try {
@@ -238,6 +241,8 @@
                 }
                 log.warn("Transaction rolled back because timeout expired.");
             }
+            // cancel the rollback task
+            cancel();
         }
     }
 



Mime
View raw message