java.util.Map.get - Is it thread safe?
By mr_mlk
@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
@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
1 person likes this