This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ConcurrentHashMap

 
sarah Marsh
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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

Thanks!
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic