This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes synchronized collection wrapper classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "synchronized collection wrapper classes?" Watch "synchronized collection wrapper classes?" New topic
Author

synchronized collection wrapper classes?

Pal Sudarshan
Ranch Hand

Joined: Jun 10, 2004
Posts: 52
As I have read, Collection classes are not synchronized. Therefore, using them in multithreaded programs may cause errors. That is the reason Sun designed syncrhonization wrappers for the Collections. I don't understand why there is a need for synchronized wrapper classes because don't programmers usually use data strucutres within methods, and if programmers make their methods synchronized, then there is no need for wrapper classes. My question, therefore is, why are there Collection wrapper classes?
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
It is not necessary to synchronize an entire method in a class you are writing just to have threadsafe access to a Collection. That is why there are Collections that have synchronized methods.
siva raju
Ranch Hand

Joined: Oct 10, 2003
Posts: 37
As i understand it, first we had synch. classes like vector and Hashtable. Because of performance issues, they later provided non-synch. collections like ArrayList and HashMap.


Siva<br />-----<br />SCWCD 1.4, SCJP 1.4, SCBCD(Preparing), CCNA
 
GeeCON Prague 2014
 
subject: synchronized collection wrapper classes?