Pergunta de entrevista da empresa Persistent Systems

How concurrent Hashmap works ?

Respostas da entrevista

Sigiloso

30 de jan. de 2025

ConcurrentHashMap in Java allows concurrent access by multiple threads while ensuring thread safety. It achieves this by: Segmented Locking– Uses multiple locks for different segments to allow concurrent writes. Bucket-Level Synchronization – Uses a combination of CAS (Compare-And-Swap), synchronized, and optimistic reads to improve performance. Thread-Safe Reads and Writes – Read operations are non-blocking, while writes use minimal locking. No Null Keys or Values – Unlike HashMap, ConcurrentHashMap does not allow null keys or values. It provides higher performance than Hashtable and Collections.synchronizedMap() in multi-threaded environments

Sigiloso

30 de jan. de 2025

ConcurrentHashMap in Java allows concurrent access by multiple threads while ensuring thread safety. It achieves this by: Segmented Locking– Uses multiple locks for different segments to allow concurrent writes. Bucket-Level Synchronization – Uses a combination of CAS (Compare-And-Swap), synchronized, and optimistic reads to improve performance. Thread-Safe Reads and Writes – Read operations are non-blocking, while writes use minimal locking. No Null Keys or Values – Unlike HashMap, ConcurrentHashMap does not allow null keys or values. It provides higher performance than Hashtable and Collections.synchronizedMap() in multi-threaded environments