• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If i use a Collections.synchronizedList () i still need to synchronize that list.

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i use a Collections.synchronizedList () i still need to synchronize that list.


Then what is the use of using this method Collections.synchronizedList ()

Please suggest your ideas.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a synchronizedList return value, all individual methods are synchronized. So you can make a single call to add, remove or get and be sure that that add / removal / retrieval is executed atomically. However, it does not make compound statements atomic. Adding two elements after each other is still not an atomic operation, and neither is iterating over it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic