• 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 in java

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I searched on net about ConcurrentHashMap but not able to understand it fully.

Could you please share any good link or explain about why to use ConcurrentHashMap and how it works?

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Performance is *usually* the reason you'd use a ConcurrentHashMap over a "regular" synchronized HashMap.
Why??

Because:

1.) Writing to a ConcurrentHashMap locks only a portion of the map;
2.) Reads can generally occur without locking.

HOWEVER, that doesn't mean you can just replace all of your HashMap variables with ConcurrentHashMap variables and your code will run
flawlessly. You need, at a minimum, to replace all the "puts" with putIfAbsent.
HIGHLY recommend Java Concurrency In Practice by Brian Goetz (and others).

Hope this helps!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

anish jain wrote:I searched on net about ConcurrentHashMap but not able to understand it fully.

Could you please share any good link or explain about why to use ConcurrentHashMap and how it works?



All about ConcurrentHashMap:
http://javaopensourcecode.blogspot.com/2012/06/concurrenthashmap.html
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lanny Gilbert wrote:You need, at a minimum, to replace all the "puts" with putIfAbsent.



No, you wouldn't just blindly do that. The two have different semantics.
 
Your buns are mine! But you can have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic