Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

where we need ConcurrentHashMap ?????  RSS feed

 
ramakrishna rayudu
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,,,,

i have Big Question that where we need this ConcurrentHashMap ???

thanks
Ramakrishna Rayudu
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a multi-threaded environment where we need a key-value datastructure.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a multi-threaded environment where we need a mutable key-value datastructure.
 
ramakrishna rayudu
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why dont we use the HashMap in that case.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because ConcurrentHashMap has far better concurrent performance that you would get with a synchronized HashMap. The javadocs of ConcurrentHashMap go into more detail on this.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And because if you used an unsynchronized HashMap, it would be even faster, but unreliable - sometimes giving incorrect results, and on rare occasions throwing nonsensical exceptions for no apparent reason. Extremely difficult to understand or debug.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!