File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Safe Collection classes? 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 "Thread Safe Collection classes?" Watch "Thread Safe Collection classes?" New topic
Author

Thread Safe Collection classes?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

Can anyone tell me which classes in the Collection interface are thread safe?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
Jothi,
Hashtable and Vector has the methods which are syncronized and are thread safe.
Syncronized collections can be made through the utility methods in Collections class from the existing collection.


~Sanjeev Singh<br />SCJP 1.5
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Thanks Sanjeev. By the way, what it means "Syncronized collections can be made through the utility methods in Collections class from the existing collection."??
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
Please look into the Collections utility class.
It has six syncronizedXxxx()methods which returns a syncronized collection.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Allright, I'll get back to this tonight after I finish perusing through Collections class.
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi Jothi,

there are methods in java.util.Collections that return a thread safe collection from a non thread safe one.
All these methods names start with "synchronized".
e.g.
List<Double> list = new ArrayList<Double>();
List<Double> safe;
safe = Collections.synchronizedList(list);


Yours,
Bu.


all events occur in real time
 
Don't get me started about those stupid light bulbs.
 
subject: Thread Safe Collection classes?
 
Similar Threads
vetor thread safe?
What is synchronizedCollection(..)..
thread safe
Collection Class Implementation Features (Contributions Requested)
Tracking "free" lines in a dedicated set