EDIT: removed false information
In any case, the synchronized
keyword is a safe bet. It blocks any threads from accessing the object while inside a synchronized
block.
// Anything can modify map at this point, making it not thread safe
map.get(0);
as opposed to
// Nothing can modify map until the synchronized block is complete
synchronized(map) {
map.get(0);
}