Fix synchronization issue

- synchronizedMultiMaps needs to be synchronized,
  when iterating over it's contents.
  See:
   http://static.javadoc.io/com.google.guava/guava/18.0/com/google/common/collect/Multimaps.html#synchronizedMultimap(com.google.common.collect.Multimap)

Change-Id: I398079a67e9fab58edc9d6f0295169939e640ba2
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java b/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
index 1f3f852..5ebc812 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
@@ -375,7 +375,12 @@
             }
 
             // TODO should we recompile on available==true?
-            delegate.triggerCompile(ImmutableSet.copyOf(intentsByDevice.get(id)), available);
+
+            final ImmutableSet<Key> snapshot;
+            synchronized (intentsByDevice) {
+                snapshot = ImmutableSet.copyOf(intentsByDevice.get(id));
+            }
+            delegate.triggerCompile(snapshot, available);
         }
     }
 
diff --git a/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java b/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java
index fbc2c88..6ea7c22 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java
@@ -443,7 +443,10 @@
         public void event(ApplicationEvent event) {
             if (event.type() == APP_UNINSTALLED || event.type() == APP_DEACTIVATED) {
                 ApplicationId appId = event.subject().id();
-                List<DefaultAsyncConsistentMap> mapsToRemove = ImmutableList.copyOf(mapsByApplication.get(appId));
+                List<DefaultAsyncConsistentMap> mapsToRemove;
+                synchronized (mapsByApplication) {
+                    mapsToRemove = ImmutableList.copyOf(mapsByApplication.get(appId));
+                }
                 mapsToRemove.forEach(DatabaseManager.this::unregisterMap);
                 if (event.type() == APP_UNINSTALLED) {
                     mapsToRemove.stream().filter(map -> map.purgeOnUninstall()).forEach(map -> map.clear());