Skip to content

Commit eff90aa

Browse files
committed
fix the concurrent issue in SpringValueRegistry.scanAndClean
1 parent af2e2dd commit eff90aa

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Apollo Java 2.4.0
1212
* [Feature Support Kubernetes ConfigMap cache for Apollo java, golang client](https://github.com/apolloconfig/apollo-java/pull/79)
1313
* [Feature support pulling configuration information from multiple AppIds](https://github.com/apolloconfig/apollo-java/pull/70)
1414
* [Fix monitor arg cause npe](https://github.com/apolloconfig/apollo-java/pull/86)
15+
* [Fix the concurrent issue in SpringValueRegistry.scanAndClean](https://github.com/apolloconfig/apollo-java/pull/95)
1516

1617
------------------
1718
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/4?closed=1)

apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ private void scanAndClean() {
8484
Iterator<Multimap<String, SpringValue>> iterator = registry.values().iterator();
8585
while (!Thread.currentThread().isInterrupted() && iterator.hasNext()) {
8686
Multimap<String, SpringValue> springValues = iterator.next();
87-
Iterator<Entry<String, SpringValue>> springValueIterator = springValues.entries().iterator();
88-
while (springValueIterator.hasNext()) {
89-
Entry<String, SpringValue> springValue = springValueIterator.next();
90-
if (!springValue.getValue().isTargetBeanValid()) {
91-
// clear unused spring values
92-
springValueIterator.remove();
87+
synchronized (springValues) {
88+
Iterator<Entry<String, SpringValue>> springValueIterator = springValues.entries()
89+
.iterator();
90+
while (springValueIterator.hasNext()) {
91+
Entry<String, SpringValue> springValue = springValueIterator.next();
92+
if (!springValue.getValue().isTargetBeanValid()) {
93+
// clear unused spring values
94+
springValueIterator.remove();
95+
}
9396
}
9497
}
9598
}

0 commit comments

Comments
 (0)