• Post Reply Bookmark Topic Watch Topic
  • New Topic

Collections, How to make collection thread safe.  RSS feed

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Q.Can anyone tell me how to make collection class threadsafe, which methods to use.
 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Collections class has a series of methods for wrapping the different collection classes in synchronized wrappers ie for Lists you would use:
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternate approach may be use Threadsafe collections like Vector, Hashtable etc but these Threadsafe collections do have performance impact ....
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhay Agarwal wrote:Alternate approach may be use Threadsafe collections like Vector, Hashtable etc but these Threadsafe collections do have performance impact ....


No more so than any other standard approach. The reason not to use these classes has nothing to do with performance, but rather, it's because they're legacy classes that were retro-fitted into the Collections Framework. They have additional non-standard methods.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!