This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes If i use a Collections.synchronizedList ()  i still need to synchronize that list. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "If i use a Collections.synchronizedList ()  i still need to synchronize that list." Watch "If i use a Collections.synchronizedList ()  i still need to synchronize that list." New topic
Author

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

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
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.


If you want something you never had do something which you had never done
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: If i use a Collections.synchronizedList () i still need to synchronize that list.
 
Similar Threads
Problems with Multithreading and Collections
In what cases we would generally use a Vector class??
Just finished my first java program :-) Can you please give me suggestions on making my code better?
Speed of Collections, etc
ConcurrentModificationException inside a synchronized method