[jboss-svn-commits] JBL Code SVN: r34699 - labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/atsintegration/classes/com/arjuna/ats/jbossatx.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 13 05:26:21 EDT 2010


Author: jhalliday
Date: 2010-08-13 05:26:21 -0400 (Fri, 13 Aug 2010)
New Revision: 34699

Modified:
   labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/atsintegration/classes/com/arjuna/ats/jbossatx/BaseTransactionManagerDelegate.java
Log:
Improve BaseTransactionManagerDelegate.findLock concurrency. JBTM-772


Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/atsintegration/classes/com/arjuna/ats/jbossatx/BaseTransactionManagerDelegate.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/atsintegration/classes/com/arjuna/ats/jbossatx/BaseTransactionManagerDelegate.java	2010-08-13 09:26:11 UTC (rev 34698)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/atsintegration/classes/com/arjuna/ats/jbossatx/BaseTransactionManagerDelegate.java	2010-08-13 09:26:21 UTC (rev 34699)
@@ -251,22 +251,29 @@
         Map locks; // <TransactionLocal, TransactionLocalLock>
         // ideally for performance we should sync on the tx instance itself but that may have nasty
         // side effects so we use something else as the lock object for the sync block
-        synchronized (LOCKS_MAP) {
-            // ensure there is a holder for lock storage on the given tx instance.
-            locks = (Map) transactionImple.getTxLocalResource(LOCKS_MAP);
-            if (locks == null) {
-                locks = new HashMap(); // <TransactionLocal, TransactionLocalLock>
-                transactionImple.putTxLocalResource(LOCKS_MAP, locks);
+        locks = (Map) transactionImple.getTxLocalResource(LOCKS_MAP);
+        // this is not a double-check locking anti-pattern, because locks
+        // is a local variable and thus can not leak.
+        if (locks == null) {
+            synchronized (LOCKS_MAP) {
+                // ensure there is a holder for lock storage on the given tx instance.
+                locks = (Map) transactionImple.getTxLocalResource(LOCKS_MAP);
+                if (locks == null) {
+                    locks = new HashMap(); // <TransactionLocal, TransactionLocalLock>
+                    transactionImple.putTxLocalResource(LOCKS_MAP, locks);
+                }
             }
         }
 
-        TransactionLocalLock transactionLocalLock;
-        synchronized (locks) {
-            // ensure there is a lock for the specified local+tx tuple
-            transactionLocalLock = (TransactionLocalLock)locks.get(local);
-            if (transactionLocalLock == null) {
-                transactionLocalLock = new TransactionLocalLock();
-                locks.put(local, transactionLocalLock);
+        TransactionLocalLock transactionLocalLock = (TransactionLocalLock) locks.get(local);
+        if (transactionLocalLock == null) {
+            synchronized (locks) {
+                // ensure there is a lock for the specified local+tx tuple
+                transactionLocalLock = (TransactionLocalLock)locks.get(local);
+                if (transactionLocalLock == null) {
+                    transactionLocalLock = new TransactionLocalLock();
+                    locks.put(local, transactionLocalLock);
+                }
             }
         }
 



More information about the jboss-svn-commits mailing list