aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question 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 "Question synchronized " Watch "Question synchronized " New topic
Author

Question synchronized

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
Hello ranchers,

Bettwen Hastable and HashMap.HashMap is synchronize / hashtable. Can anyone tell correct answer.
If HashMap is synchronized , then how can we synchronized it.
Same for Vector, Arraylist and LinkeList, among these which one is synchronized. How can we synchronized them.

Thanks
Dinesh


Thanks<br />Dinesh
Nadeem Khan
Ranch Hand

Joined: Nov 27, 2007
Posts: 108
I think Hashtable is synchronized. And these are standard java API and if one of them is synchronized, that simply means that their implementation present in API provides a synchornized access! But you can apply your own synchronization methods/blocks while using them in your code!


<i>If there were no Exceptions (not Errors!), Life would have kinda sucked!!</i>
Sunny Malik
Ranch Hand

Joined: Dec 30, 2007
Posts: 86
Hashtable is synchronized not Hashtable
Vector is synchronized not ArrayList
you do not need to worry about synchronization while using these collection...synchronized means methods in that classs are synchronized


Research is what I'm doing when I dont know what I'm doing
Rah Gupta
Greenhorn

Joined: Nov 20, 2007
Posts: 3
Hello,

There are two ways to make a hashmap synchronized. One is to call synchronized Map on Collections class and 2nd is to make your own class.
For eg.

Class MyMap extends HashMap {


public synchronized void put(...) {
super.put(...);
}

public synchronized void get(...) {
super.put(...);
}
}

similarly you can synchronized all the methods. So intead of creating an object of HashMap you will be creating an object og MyMap
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question synchronized