diff --git a/CHANGES.md b/CHANGES.md index a8e204cf..7705f8ea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Apollo Java 2.4.0 * [Feature Support Kubernetes ConfigMap cache for Apollo java, golang client](https://github.com/apolloconfig/apollo-java/pull/79) * [Feature support pulling configuration information from multiple AppIds](https://github.com/apolloconfig/apollo-java/pull/70) * [Fix monitor arg cause npe](https://github.com/apolloconfig/apollo-java/pull/86) +* [Fix the concurrent issue in SpringValueRegistry.scanAndClean](https://github.com/apolloconfig/apollo-java/pull/95) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/4?closed=1) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java index 2600960e..db2467b4 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java @@ -84,12 +84,15 @@ private void scanAndClean() { Iterator> iterator = registry.values().iterator(); while (!Thread.currentThread().isInterrupted() && iterator.hasNext()) { Multimap springValues = iterator.next(); - Iterator> springValueIterator = springValues.entries().iterator(); - while (springValueIterator.hasNext()) { - Entry springValue = springValueIterator.next(); - if (!springValue.getValue().isTargetBeanValid()) { - // clear unused spring values - springValueIterator.remove(); + synchronized (springValues) { + Iterator> springValueIterator = springValues.entries() + .iterator(); + while (springValueIterator.hasNext()) { + Entry springValue = springValueIterator.next(); + if (!springValue.getValue().isTargetBeanValid()) { + // clear unused spring values + springValueIterator.remove(); + } } } }