aspose file tools*
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 Spring in Action this week in the Spring 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
Author

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 ).
TIA,
Rick
Rob Ross
Bartender

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.


Rob
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
Sheriff

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
 
Don't get me started about those stupid light bulbs.
 
subject: How are Vector and Hashtable synchronized?