In some android open source code I found
private Map<ImageView, String> imageViews=Collections.synchronizedMap(new
WeakHashMap<ImageView, String>());
can any one explain me difference between Normal Map and collections.synchronizedmap
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The regular Map implementations in java.util package are not thread safe. This means that if multiple threads are doing
get()orput()operations on the same Map, it may result in race conditions or inconsistent data in the Map.To use an existing Map in a multi-threaded environment, you can get a synchronized instance of the same by calling
Collections.synchronizedMap(). On such instances, most of the methods likeget(),putandkeyset()are synchronized and can be safely used concurrently.For more information on this, refer to
http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#synchronizedMap(java.util.Map)