The Maps.synchronizedBiMap()
method states that
it is imperative that the user manually synchronize on the returned map when accessing any of its collection views.
Does this include the inverse()
view of the BiMap? For example, if the variables are initialized as in the following example, can invoking inverse.put()
from other threads be problematic (e.g. the change is not visible in a get()
call on either map
or inverse
, even if put
happened-before get
)?
BiMap<Object, Object> map = Maps.synchronizedBiMap(HashBiMap.create());
BiMap<Object, Object> inverse = map.inverse();
If this is in fact a problem, is there a standard/recommended way of solving this?
// EDIT
Looking at the implementation, it seems like the inverse()
of a SynchronizedBiMap
is also a SynchronizedBiMap
, sharing the same mutex
. Does this mean the described problem is non-existent? Confirmation from a Guava Collections expert would be much appreciated ;)