Fix ConcurrentModificationException when accumulating service testers RCL_2_4
authorEd Swartz <ed.swartz@nokia.com>
Fri, 23 Apr 2010 08:22:24 -0500
branchRCL_2_4
changeset 1261 c144540186fe
parent 1258 33a822a05021
child 1262 f88340f6e139
Fix ConcurrentModificationException when accumulating service testers
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ServiceTester.java
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ServiceTester.java	Wed Apr 21 14:31:25 2010 -0500
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ServiceTester.java	Fri Apr 23 08:22:24 2010 -0500
@@ -18,6 +18,7 @@
 package com.nokia.carbide.remoteconnections.internal;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -89,13 +90,15 @@
 	}
 	
 	private ServiceTester() {
-		registry = new HashSet<AbstractConnectedService2>();
+		registry = Collections.synchronizedSet(new HashSet<AbstractConnectedService2>());
 		runningThreads = new HashSet<TestRunner>();
 		Thread t = new Thread(new Runnable() {
 			public void run() {
 				while (true) {
-					Collection<Set<AbstractConnectedService2>> csSetsByResource = 
-						createConnectedServiceSetsByResource(new HashSet<AbstractConnectedService2>(registry));
+					Collection<Set<AbstractConnectedService2>> csSetsByResource;
+					synchronized (registry) {
+						csSetsByResource = createConnectedServiceSetsByResource(new HashSet<AbstractConnectedService2>(registry));
+					}
 					for (Set<AbstractConnectedService2> set : csSetsByResource) {
 						Collection<Set<AbstractConnectedService2>> csSetsByService = 
 							createConnectedServiceSetsByService(set);