I\'m trying to create a concurrent LinkedHashMap for a multithreaded architecture.
If I use Collections#synchronizedMap()
, I would have to use synchroni
A LinkedHashMap
has a doubly linked list running through a hashtable. A FIFO only mutates the links on a write (insertion or removal). This makes implementing a version fairly straightforward.
#put()
/ #putIfAbsent()
/ #remove()
with a lock.On iteration, no lock is needed as you can safely follow the "next" field. Reads can be lock-free by just delegating to the CHM on a #get()
.