[concurrency-interest] Concurrent Bidirectional Map
normelton at gmail.com
Sun Nov 22 14:54:28 EST 2009
Thanks for dedicating some brain-cells to looking at this.
> Unfortunately, if you synchronize put() and remove() you lose the
> concurrency benefits of CHM. All threads will serialize behind the put lock.
Yep. My application is 99% reads and 1% writes, so I can tolerate
single-threading put() and remove() operations. One major benefit that
does remain; however, is that I don't have to worry about concurrent
modification exceptions when iterating through the map members.
I would love someone with more concurrency kung-fu to implement a real
BiMap, so that I wouldn't have to rely on synchronization.
> Also, in your implementation, in order for the bi-map-put to be perceived
> atomically, you would have to synchronize the get method as well =(
This is where I'm a little perplexed. I've synchronized any write
methods, so that the two CHMs stay "in synch". Any read operations, as
I see it, should be safe to fall through to the primary CHM without
extra synchronization. If one thread is updating the map while another
is reading, the reading thread will either get the new or the old
value, but we shouldn't get any exceptions or end up with inconsistent
Or am I misunderstanding something?
More information about the Concurrency-interest