my dog learned polymorphism*
The moose likes Java in General and the fly likes How ConcurrentHashMap is synchronized? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How ConcurrentHashMap is synchronized?" Watch "How ConcurrentHashMap is synchronized?" New topic
Author

How ConcurrentHashMap is synchronized?

jami siva
Ranch Hand

Joined: Oct 16, 2009
Posts: 63
I saw ConcurrentHashMap API class, but in that I didn't find any method or block with synchronized keyword. Then How ConcurrentHashMap is synchronized.


Thanks,
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18756
    
  40

jami siva wrote:I saw ConcurrentHashMap API class, but in that I didn't find any method or block with synchronized keyword. Then How ConcurrentHashMap is synchronized.


Like many of the java.util.concurrent classes, added with Java 5, it is made thread safe optimistically -- with the atomic libraries. This is why the ReentrantLock class, which implements the synchronized functionality, is actually faster (under many conditions).

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7696
    
  19

jami siva wrote:I saw ConcurrentHashMap API class, but in that I didn't find any method or block with synchronized keyword. Then How ConcurrentHashMap is synchronized.

Probably with ReentrantLock's, but the fact is I don't honestly know - and you don't need to either.

That's the whole point of Object-Orientation: You don't need to know how something works; you just need to know what it does.
And for more info on that subject, you might want to read the WhatNotHow (←click) page.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How ConcurrentHashMap is synchronized?