File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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
I agree. Here's the link:
subject: synchronized collection wrapper classes?
It's not a secret anymore!