|
7 | 7 |
|
8 | 8 | import java.util.Iterator; |
9 | 9 | import java.util.Map; |
| 10 | +import java.util.NoSuchElementException; |
10 | 11 | import java.util.Optional; |
11 | 12 | import java.util.concurrent.ConcurrentHashMap; |
12 | 13 | import java.util.concurrent.atomic.AtomicReference; |
@@ -48,8 +49,13 @@ public Runnable getUpdateRunnable(int maxEntryPerCall) { |
48 | 49 | public void run() { |
49 | 50 | Iterator<Map.Entry<K, UpdateStatus>> iterator = iteratorRef.updateAndGet(old -> old == null || !old.hasNext() ? map.entrySet().iterator() : old); |
50 | 51 | int count = 0; |
51 | | - while (iterator.hasNext() && count < maxEntryPerCall) { |
52 | | - Map.Entry<K, UpdateStatus> entry = iterator.next(); |
| 52 | + while (count < maxEntryPerCall) { |
| 53 | + Map.Entry<K, UpdateStatus> entry; |
| 54 | + try { |
| 55 | + entry = iterator.next(); |
| 56 | + } catch (NoSuchElementException e) { |
| 57 | + break; |
| 58 | + } |
53 | 59 | K key = entry.getKey(); |
54 | 60 | UpdateStatus updateStatus = entry.getValue(); |
55 | 61 |
|
@@ -102,8 +108,13 @@ public Runnable getSetRunnable() { |
102 | 108 | @Override |
103 | 109 | public void run() { |
104 | 110 | Iterator<Map.Entry<K, UpdateStatus>> iterator = iteratorRef.updateAndGet(old -> old == null || !old.hasNext() ? map.entrySet().iterator() : old); |
105 | | - while (iterator.hasNext()) { |
106 | | - Map.Entry<K, UpdateStatus> entry = iterator.next(); |
| 111 | + while (true) { |
| 112 | + Map.Entry<K, UpdateStatus> entry; |
| 113 | + try { |
| 114 | + entry = iterator.next(); |
| 115 | + } catch (NoSuchElementException e) { |
| 116 | + break; |
| 117 | + } |
107 | 118 | UpdateStatus updateStatus = entry.getValue(); |
108 | 119 |
|
109 | 120 | if (updateStatus != UpdateStatus.RESET && !(updateStatus instanceof UpdateStatus.Set)) { |
|
0 commit comments