Commit f17e7ea8 authored by Jason Song's avatar Jason Song

fix concurrent modification exception

parent 9bf33f70
...@@ -27,7 +27,6 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -27,7 +27,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.DeferredResult;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -133,13 +132,15 @@ public class NotificationController implements MessageListener { ...@@ -133,13 +132,15 @@ public class NotificationController implements MessageListener {
new ResponseEntity<>( new ResponseEntity<>(
new ApolloConfigNotification(keys.get(2)), HttpStatus.OK); new ApolloConfigNotification(keys.get(2)), HttpStatus.OK);
Collection<DeferredResult<ResponseEntity<ApolloConfigNotification>>> //create a new list to avoid ConcurrentModificationException
results = deferredResults.get(message); List<DeferredResult<ResponseEntity<ApolloConfigNotification>>> results =
Lists.newArrayList(deferredResults.get(message));
logger.info("Notify {} clients for key {}", results.size(), message); logger.info("Notify {} clients for key {}", results.size(), message);
for (DeferredResult<ResponseEntity<ApolloConfigNotification>> result : results) { for (DeferredResult<ResponseEntity<ApolloConfigNotification>> result : results) {
result.setResult(notification); result.setResult(notification);
} }
logger.info("Notification completed");
} }
private void logWatchedKeysToCat(List<String> watchedKeys, String eventName) { private void logWatchedKeysToCat(List<String> watchedKeys, String eventName) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment