Is it safe to get values from a java.util.HashMap from multiple threads (no modification)?

Jeremy Manson, the god when it comes to the Java Memory Model, has a three part blog on this topic – because in essence you are asking the question “Is it safe to access an immutable HashMap” – the answer to that is yes. But you must answer the predicate to that question which is – “Is my HashMap immutable”. The answer might surprise you – Java has a relatively complicated set of rules to determine immutability.

For more info on the topic, read Jeremy’s blog posts:

Part 1 on Immutability in Java:
http://jeremymanson.blogspot.com/2008/04/immutability-in-java.html

Part 2 on Immutability in Java:
http://jeremymanson.blogspot.com/2008/07/immutability-in-java-part-2.html

Part 3 on Immutability in Java:
http://jeremymanson.blogspot.com/2008/07/immutability-in-java-part-3.html

Leave a Comment