Thursday, May 29, 2008

ConcurrentHashMap

Why use the ConcurrentHashMap? The traditional synchronized HashMap or Hashtable, use a single lock to read and write. When you try to write new entry while other try to read the different entry, the locking happened. Shouldn't be like this. The simple implementation is using a N lock for N entries. The modification for entry X will be use the Y lock, where Y is lock for X. On ConcurrentHashMap, they use segmentation for the lock, they have 32 lock (or depends on the configuration). So a different write or read can be done concurrently without locking if they have a different lock/segment.

No comments: