• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ConcurrentHashMap

 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Why is the word "abbreviation" so long? And this ad is so short?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic