Take an unsynchronised map
Map<Long,Long> map = new HashMap<>();
When we do a map.put(1,2)
from one thread, if is possible for some other thread to not see this updated value? I understand how primitives and references can be cached and therefore, synchronisation is needed when they are accessed. But what about the values inside the object itself?
So say one thread does:
map.put(1,2)
And other thread does
map.get(1)
Is it possible for this thread to see null
(assuming this thread has the updated reference to the map
)? I presume that it should always see the updated value because the object cannot be cached by any thread.