Commit 6975f84
committed
feat: add ConcurrentSkipListMapExample with concurrent writers
What
- Implemented `ConcurrentSkipListMapExample` demo.
- Demonstrates concurrent writes + iteration using `ConcurrentSkipListMap`.
- Showcases sorted operations (`firstKey`, `lastKey`, `subMap`).
Why
- To illustrate how `ConcurrentSkipListMap` behaves under concurrent updates.
- Highlights weakly-consistent iterators that tolerate concurrent modifications.
- Shows real-time insertion by two threads (odd/even writers).
How
- Created `ConcurrentSkipListMap<Integer, String>`.
- Preloaded keys `50`, `10`, `30`, `70`.
- Spawned two threads:
- `writer-odd` → inserts odd keys with values `"vX"`.
- `writer-even` → inserts even keys with values `"vX"`.
- Iterated concurrently over `map.entrySet()` (may reflect partial updates).
- After joining threads, printed:
- First/last key
- A submap view `[10..30]`.
Logic
- Iteration is weakly-consistent → doesn’t throw `ConcurrentModificationException`.
- Map maintains natural ordering of keys.
- Range queries like `subMap`, `headMap`, `tailMap` work efficiently.
Real-world use
- Thread-safe sorted maps for caches, leaderboards, or time-series data.
- Useful when concurrent writes + ordered reads are required.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 5ef321f commit 6975f84
File tree
1 file changed
+48
-0
lines changed- Section 25 Collections Frameworks/Map Interface/Concurrent HashMap/Concurrent Skip List Map/src
1 file changed
+48
-0
lines changedLines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
0 commit comments