Reputation: 14655
As I understand both maps are designed to work in multithreaded enviroment. But I intereted in what features they guarantee(i.e. availability, consistency).
Upvotes: 1
Views: 458
Reputation: 110054
I believe they don't use read locks (relying on volatile
fields to ensure that reads see writes from other threads) and are internally broken down into some number of segments (based on the expected concurrency level) that entries are distributed among, each of which uses its own write lock separate from the others. That way reads never block and writes only block if they happen to need to write to the same segment at the same time. I'm no expert on it though.
As far as guarantees, I'm not sure what you're asking. ConcurrentMap
specifies a memory consistency guarantee:
Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a
ConcurrentMap
as a key or value happen-before actions subsequent to the access or removal of that object from theConcurrentMap
in another thread.
Upvotes: 2