E
easy
I would like to apply
java.util.concurrent.locks.ReentrantReadWriteLock
on a HashMap(or ConcurrentHashMap)
Most examples on internet applies ReadWriteLock on whole map.
that is, every setter/write (whatever which "field") on map will block
other getter (read) operation or other setter on different field.
because I build a cache map for DB.
the map setter will occurs when read miss.
In the setter the object will be load from DB, and it may very time-
consumed.
Can I give each "field" of map its own "ReadWriteLock"? rather than
Lock on whole map.
(every new field should be given a new ReadWriteLock.)
(w/r on a "field" will not affect other field.)
I do not know if it will have better performance.
(when loading DB and setting it to a field, other read operation on
other field will not be bocked.)
or is that bad
when too many Lock object created.(there may be many many fields in
map)
does someone have idea?
java.util.concurrent.locks.ReentrantReadWriteLock
on a HashMap(or ConcurrentHashMap)
Most examples on internet applies ReadWriteLock on whole map.
that is, every setter/write (whatever which "field") on map will block
other getter (read) operation or other setter on different field.
because I build a cache map for DB.
the map setter will occurs when read miss.
In the setter the object will be load from DB, and it may very time-
consumed.
Can I give each "field" of map its own "ReadWriteLock"? rather than
Lock on whole map.
(every new field should be given a new ReadWriteLock.)
(w/r on a "field" will not affect other field.)
I do not know if it will have better performance.
(when loading DB and setting it to a field, other read operation on
other field will not be bocked.)
or is that bad
when too many Lock object created.(there may be many many fields in
map)
does someone have idea?