Is Hashmap thread safe? how to make it thread safe?

It is not thread safe. because when we use put/get, or put/put the same time, there will be problems
how to make it safe? don’t use them, instead, use collections.synchronizedMap() or concurrentHashMap or hashtable.
but not many people use hashtable, because even though it is thread safe, it just lock the whole table when it’s read or write, so it has low efficient.
so what’s the difference between synchronizedMap and concurrentHashmap. and it’s clearly that the concurrentHashmap is a better choice.

在这里插入图片描述

posted @ 2020-10-28 01:53  EvanMeetTheWorld  阅读(25)  评论(0)    收藏  举报