A quote from #JCIP :
\"Since a ConcurrentHashMap cannot be locked for exclusive access, we cannot use client-side locking to create new atomic operatio
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
.