[jbosscache-commits] JBoss Cache SVN: r8496 - core/trunk/src/main/java/org/jboss/cache/interceptors.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Jun 5 19:57:34 EDT 2012


Author: dereed
Date: 2012-06-05 19:57:33 -0400 (Tue, 05 Jun 2012)
New Revision: 8496

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
Log:
[JBCACHE-1613] Fix data corruption between threads when using JTS transaction manager


Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java	2012-06-05 23:45:24 UTC (rev 8495)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java	2012-06-05 23:57:33 UTC (rev 8496)
@@ -896,6 +896,13 @@
 
       public void beforeCompletion()
       {
+          beforeCompletion(true);
+      }
+
+      // resetInvocationContext=false should be used by sub classes that call
+      // invocationContextContainer.remove themselves
+      protected void beforeCompletion(boolean resetInvocationContext)
+      {
          if (trace) log.trace("Running beforeCompletion on gtx " + gtx);
 
          if (transactionContext == null)
@@ -916,6 +923,11 @@
          assertCanContinue();
 
          ctx.setOriginLocal(false);
+
+         // JBCACHE-1613: remove the ThreadLocal reference to ctx, in case a different 
+         // thread calls afterCompletion
+         if(resetInvocationContext)
+            invocationContextContainer.remove();
       }
 
       // this should really not be done here -
@@ -935,6 +947,10 @@
             }
          }
 
+         // JBCACHE-1613: Make sure our ThreadLocal is set to ctx, in case beforeCompletion
+         // was called with a different thread
+         invocationContextContainer.set(ctx);
+
          try
          {
             assertCanContinue();
@@ -1068,7 +1084,7 @@
       @Override
       public void beforeCompletion()
       {
-         super.beforeCompletion();
+         super.beforeCompletion(false);
          ctx.setOriginLocal(!remoteLocal); // this is the LOCAL sync handler after all!
          // fetch the modifications before the transaction is committed
          // (and thus removed from the txTable)
@@ -1140,6 +1156,10 @@
             localRollbackOnly = false;
             setTransactionalContext(null, null, null, ctx);
             ctx.setOptionOverrides(originalOptions);
+
+            // JBCACHE-1613: remove the ThreadLocal reference to ctx, in case a different 
+            // thread calls afterCompletion
+            invocationContextContainer.remove();
          }
       }
 



More information about the jbosscache-commits mailing list