my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How are Vector and Hashtable synchronized? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How are Vector and Hashtable synchronized?" Watch "How are Vector and Hashtable synchronized?" New topic

How are Vector and Hashtable synchronized?

Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
The API mentions that Vector and Hashtable are synchronized. I'm curious what actually is synchronized and how I could tell from the API that it is synchronized? You can't synchronize a class and none of the methods that I can see listed have the modifier synchronized so what is that is actually makes these classes synchronized? ( I know I don't need to know much more than that they are synchronized for the test, but I'm just curious ).
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
The synchronized keyword is an implementation detail, like native, so it's not going to show up in the API docs.
Basically, every call in Vector and Hastable that gets an object, or sets an object, is synchronized. If you really want to look at the methods themselves, look at the source code for Vector and Hashtable. Source for all the Java classes comes with the JDK, usually in a file called src.jar.

SCJP 1.4
Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
Thanks, Rob, that makes sense. I didn't think of it synchronizing on the objects which I'd only see in implementation within the source code.
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

You can in fact synchronize a class, or rather the object-invariant fields of the class, by declaring one or more of its static methods to be synchronized.

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Consider Paul's rocket mass heater.
subject: How are Vector and Hashtable synchronized?
Similar Threads
How to make ArraList and HashMap methods synchronized
ArrayList and Vector
HashMap or HashTable