[jboss-svn-commits] JBL Code SVN: r31496 - labs/jbosstm/branches/JBOSSTS_4_2_3_SP5_CP04_JBTM_365/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Feb 8 15:41:32 EST 2010


Author: jbertram at redhat.com
Date: 2010-02-08 15:41:32 -0500 (Mon, 08 Feb 2010)
New Revision: 31496

Modified:
   labs/jbosstm/branches/JBOSSTS_4_2_3_SP5_CP04_JBTM_365/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TwoPhaseCoordinator.java
Log:
JBPAPP-2091

Modified: labs/jbosstm/branches/JBOSSTS_4_2_3_SP5_CP04_JBTM_365/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TwoPhaseCoordinator.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_SP5_CP04_JBTM_365/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TwoPhaseCoordinator.java	2010-02-08 19:31:29 UTC (rev 31495)
+++ labs/jbosstm/branches/JBOSSTS_4_2_3_SP5_CP04_JBTM_365/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TwoPhaseCoordinator.java	2010-02-08 20:41:32 UTC (rev 31496)
@@ -143,11 +143,14 @@
 					}
 				}
 
-				if (_synchs.add(sr))
-				{
-					result = AddOutcome.AR_ADDED;
-				}
-			}
+                // need to guard against synchs being added while we are performing beforeCompletion processing
+                synchronized (_synchs) {
+                    if (_synchs.add(sr))
+                    {
+                        result = AddOutcome.AR_ADDED;
+                    }
+                }
+            }
 			break;
 		default:
 			break;
@@ -230,14 +233,20 @@
 			 */
 
 			int lastIndexProcessed = -1;
-			SynchronizationRecord[] copiedSynchs = (SynchronizationRecord[])_synchs.toArray(new SynchronizationRecord[] {});
+            SynchronizationRecord[] copiedSynchs;
+            // need to guard against synchs being added while we are performing beforeCompletion processing
+            synchronized (_synchs) {
+                copiedSynchs = (SynchronizationRecord[])_synchs.toArray(new SynchronizationRecord[] {});
+            }
 
 			while( (lastIndexProcessed < _synchs.size()-1) && !problem) {
 
-				// if new Synchronization have been registered, refresh our copy of the collection:
-				if(copiedSynchs.length != _synchs.size()) {
-					copiedSynchs = (SynchronizationRecord[])_synchs.toArray(new SynchronizationRecord[] {});
-				}
+                synchronized (_synchs) {
+                    // if new Synchronization have been registered, refresh our copy of the collection:
+                    if(copiedSynchs.length != _synchs.size()) {
+                        copiedSynchs = (SynchronizationRecord[])_synchs.toArray(new SynchronizationRecord[] {});
+                    }
+                }
 
 				lastIndexProcessed = lastIndexProcessed+1;
 				_currentRecord = copiedSynchs[lastIndexProcessed];
@@ -359,8 +368,10 @@
 				}
 			}
 
-			_synchs = null;
-			_currentRecord = null;
+            synchronized (_synchs) {
+                // nulling _syncs causes concurrency problems, so dispose contents instead:
+                _synchs.clear();
+            }
 		}
 
 		return !problem;



More information about the jboss-svn-commits mailing list