yura
yura

Reputation: 14655

Does Guava MapMaker and JDK ConcurrentMap uses read/write lock?

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

Answers (1)

ColinD
ColinD

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 the ConcurrentMap in another thread.

Upvotes: 2

Related Questions