cow: CopyOnWriteArrayList - deterministic iterator-snapshot and synchronizedList CME demos, JMH read/write throughput, and the addLast/removeFirst fix for a real concurrent-writer race
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
list before any iterator is taken = [Apple, Banana, Cherry]
|
||||
beforeWrite.next() = Apple
|
||||
[writer] added Date and Elderberry - list is now [Apple, Banana, Cherry, Date, Elderberry]
|
||||
|
||||
=== beforeWrite iterator was created BEFORE the write - draining the rest of it ===
|
||||
beforeWrite.next() = Banana
|
||||
beforeWrite.next() = Cherry
|
||||
beforeWrite never saw Date or Elderberry, and threw no exception.
|
||||
|
||||
=== afterWrite iterator is created AFTER the write - it sees the current array ===
|
||||
afterWrite.next() = Apple
|
||||
afterWrite.next() = Banana
|
||||
afterWrite.next() = Cherry
|
||||
afterWrite.next() = Date
|
||||
afterWrite.next() = Elderberry
|
||||
|
||||
Final list = [Apple, Banana, Cherry, Date, Elderberry]
|
||||
Reference in New Issue
Block a user