Hashtable
Iteration methods behaviour: If a thread tries to modify the map while another thread is iterating over it — such as keySet(), values(), and entrySet() — , the modifying thread will be blocked until the iteration is complete.
Thread-safe. Slow Performance because only one thread can work at a time in the entire table. Not allow null key and null values. |
SyncronizedMap
Iteration methods behaviour: The main difference from Hashtable is that synchronizedMap throws a ConcurrentModificationException if a thread tries to modify the map while another thread is iterating over it using methods — such as keySet(), values(), and entrySet().
Thread-safe. Slow Performance because only one thread can work at a time in the entire table. Allow null key and null values. |
ConcurrentHashMap
Weak consistency: ConcurrentHashMap has weak consistency, which means that the iteration may reflect some, but not all, of the modifications that were made to the map during iteration. So it allows multiple threads to read from the map simultaneously, without blocking each other. But if there is a writing thread running in the meantime, reading from the map could get “old” or inconsistent values.
Post a Comment