java - How can I allow concurrent writes on different parts (with different keys) of a guava multimap -
I am using Google Guava Multimode and would like to know whether permission to write concurrently in different parts of the map is possible Or do I have to synchronize all access? When I say different parts, I mean that different key pairs are added to the value.
Is the following sample code correct?
class key {} class value {} private multimap & lt; Key, value & gt; Multimap = Hashmiltmap.Create (); Private Final Striped & lt; Key & gt; Locks = Stripped. Redroit Lock (100); Write public null (last key key, final collection & lt; value & gt; value) {lock lock lock = lock.get (key) .writeLock (); WriteLock.lock (); Try {for (value value: value) {multimap.put (key, value); }} Finally {writeLock.unlock (); }} Public collection & lt; Price & gt; Read (Last key) {lock readLock = locks.get (key) .readLock (); ReadLock.lock (); {// archive value} Finally try {readLock.unlock (); }}
Comments
Post a Comment