java.util.Map.get - Is it thread safe?

@mr_mlk (364)
June 29, 2007 10:18am CST
Good morning all, I have always thought of methods that do not alter the internal state of a collection as inherently thread safe, however I'm now getting different data to what I expect. So, as per the title, do you know is the get( Object ) method of HashMap is thread safe? Thanks very much Mike
2 people like this
2 responses
@raghwagh (1527)
• India
7 Jul 07
Hi friend whatever solution the friend above me has provided is perfectly correct.I will like to add to this that similar to map you can have other collections also thread safe in similar manner.
1 person likes this
@senthil2k (1500)
• India
29 Jun 07
If your question is about HashMap, then the answer is : Hashmap is not Thread Safe. You need to synchronize it externally like, Map m = Collections.synchronizedMap(new HashMap(...)); For more information, see the link below, http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html