Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Safe Collection classes?  RSS feed

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Can anyone tell me which classes in the Collection interface are thread safe?
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please look into the Collections utility class.
It has six syncronizedXxxx()methods which returns a syncronized collection.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Allright, I'll get back to this tonight after I finish perusing through Collections class.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!