1 Design: A Thread-safe Hashmap
Design: A Thread-safe Hashmap
|Typical methods of hashmap||get, update, delete, exists, size|
|Avoid frequent write locking||Instead of lock the whole array, lock at smaller granularity of segments|
|To speed up lookup of conflicts||Change linked list to balanced binary search tree|
|Reference||Link: Internal Working of HashMap in Java|
|Reference||Link: How ConcurrentHashMap Works Internally in Java|
Q: How support basic hashmap?
- Eventually store data of hashmap in an array
Q: Use case of concurrent hashmap?
Q: How to avoid hashing conflict?
Q: Would there be write conflicts or dirty reads?
- Lock when updating the map
- No locking for reading values
Q: How hashmap extend the capacity? How to resize?
Q: How ConcurrentHashMap is implemented in popular programming languages?