Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hashtables are synchronized...

 
Muralidhar Gandepalli
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one throw light on why Hashtables are called synchronized ...
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most all of Hashtable's methods are synchronized to make them (mostly) thread-safe. If you don't need thread-safety (or need finer-grained control), HashMap is your friend. Java 1.5 also added ConcurrentHashMap (or some similar name) that I believe allows multiple readers simultaneously.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why they chose to synchronize it. Its synchronization is not going to preclude your own synchronization. IMHO its a design flaw and a waste of time for them to have done that.

I welcome other opinions.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by CL Gilbert:
I don't know why they chose to synchronize it.
I'd bet five bucks it was a simple matter of the early Java developers at Sun going hog-wild: "Man, it's so cool having synchronization built into the language. I wonder where else I can use it?"
 
Sathvathsan Sampath
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of time you end up with client level sychronization and would find that hashtable don't really help. HashMap serves you then.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes but hashtable and hashmap are not interchangeable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic