Why ConcurrentHashMap cannot be locked for exclusive access?

后端 未结 3 1682
旧巷少年郎
旧巷少年郎 2021-01-21 02:31

A quote from #JCIP :

\"Since a ConcurrentHashMap cannot be locked for exclusive access, we cannot use client-side locking to create new atomic operatio

3条回答
  •  野的像风
    2021-01-21 03:12

    Code you have written is your implementation, and if you use it that way then all other operations must work that way i.e. all operations must accquire same lock.

    But the main point here is that java has not provided ConcurrentHashMap for this purpose, its purpose is to allow multiple thread to work simultaneously.

    For your requirement go for HashTable.

提交回复
热议问题