File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes ConcurrentHashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "ConcurrentHashMap" Watch "ConcurrentHashMap" New topic


sarah Marsh
Ranch Hand

Joined: Mar 06, 2001
Posts: 282

As of ConcurrentHashMap: Since
Retrieval operations (including get) generally do not block, so may overlap with update operations (including put and remove).
all operations are thread-safe?

Steve Luke

Joined: Jan 28, 2003
Posts: 4181

The ConcurrentHashMap is broken up into small pieces called Segments that cover a specific range of Hashes. The Segments basically have final links to the next Node, so they can't change. Which means that a read can safely traverse from one Node to the next without worrying about interuption. When a modification makes a change to a Node it must remove the Node and insert a new one, which means it does not affect a Node that a retrieval is already using. It also always inserts the Node at the beginning of the link-list, meaning you are modifying the iteration of a get by inserting new elements as well.

Volatile variables help control where the iterations in the get occur.

I agree. Here's the link:
subject: ConcurrentHashMap
It's not a secret anymore!