Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Hashtables are synchronized...

 
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 ...
 
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.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE 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?"
 
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
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes but hashtable and hashmap are not interchangeable.
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic