How does ConcurrentHashMap work internally?

前端 未结 6 758
傲寒
傲寒 2020-12-02 07:05

I was reading the official Oracle documentation about Concurrency in Java and I was wondering what could be the difference between a Collection returned by

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 07:35

    I would read the source of ConcurrentHashMap as it is rather complicated in the detail. In short it has

    • Multiple partitions which can be locked independently. (16 by default)
    • Using concurrent Locks operations for thread safety instead of synchronized.
    • Has thread safe Iterators. synchronizedCollection's iterators are not thread safe.
    • Does not expose the internal locks. synchronizedCollection does.

提交回复
热议问题