diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-04-26 10:28:07 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-04-26 10:28:07 +0200 |
commit | 5a89596b1b1b6d7dc20afa33cb1d4b1388cb5fa7 (patch) | |
tree | 54641269a4b7d8e773152c9eff794d828ef0d0de /jrt | |
parent | 953119d5105331fa04b1c58d15ff957eeb81b7b8 (diff) |
Use AtomicReference instead of volatile.
Diffstat (limited to 'jrt')
-rw-r--r-- | jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java b/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java index c632191e31d..22abddfe924 100644 --- a/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java +++ b/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; import java.util.logging.Level; @@ -37,7 +38,7 @@ public class Mirror implements IMirror { private final BackOffPolicy backOff; private volatile int updates = 0; private boolean requestDone = false; - private volatile Entry[] specs = new Entry[0]; + private AtomicReference<Entry[]> specs = new AtomicReference<>(new Entry[0]); private int specsGeneration = 0; private final Task updateTask; private final RequestWaiter reqWait; @@ -90,7 +91,7 @@ public class Mirror implements IMirror { public List<Entry> lookup(String pattern) { ArrayList<Entry> found = new ArrayList<>(); char[] p = pattern.toCharArray(); - for (Entry specEntry : specs) { + for (Entry specEntry : specs.get()) { if (match(specEntry.getNameArray(), p)) { found.add(specEntry); } @@ -211,7 +212,7 @@ public class Mirror implements IMirror { for (int idx = 0; idx < numNames; idx++) { newSpecs[idx] = new Entry(n[idx], s[idx]); } - specs = newSpecs; + specs.set(newSpecs); specsGeneration = answer.get(2).asInt32(); int u = (updates + 1); @@ -259,7 +260,7 @@ public class Mirror implements IMirror { } } else { Map<String, Entry> map = new HashMap<>(); - for (Entry e : specs) { + for (Entry e : specs.get()) { map.put(e.getName(), e); } for (String rem : r) { @@ -275,7 +276,7 @@ public class Mirror implements IMirror { } } - specs = newSpecs; + specs.set(newSpecs); specsGeneration = diffToGeneration; int u = (updates + 1); @@ -301,7 +302,7 @@ public class Mirror implements IMirror { target.close(); target = null; } - specs = new Entry[0]; + specs.set(new Entry[0]); } /** |