Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
"The more I learn,the more,I get to know, is left to learn."
Seetharaman Venkatasamy wrote:I would prefer java.util.concurrent.CopyOnWriteArrayList rather than Collections.synchronizedList(new ArrayList(...)) or Vector
Preet Prasannan wrote:If this method does return a synchronized list, why is there a need to again put this list in a synchronized block while iterating?
Jelle Klap wrote:I personally avoid using the Vector class, because I view it as nothing more than a legacy class. If I do need a synchronized List variant I'd rather opt for the synchronized List approach. While the thread-safety benefits are the same the declaration of a synchonized List conveys, much more so than a Vector in my opinion, that carefull considerations reagarding thread-safety were made and should be adhered to.
Mike Simmons wrote:Ultimately, I think this is one of those things where early on, when Sun engineers where developing the Java language and platform, some things were done quickly, under tight deadlines, that we might today consider, ummm, errors of judgement, or inconsistencies, or at least non-intuitive choices. If they did it again today, knowing what they know now, many things would be different. But history didn't happen that way, and today we're stuck with decisions made over a decade ago.
shivendra tripathi wrote: But I never got the answer for "Why they have been introduced".
SCJP 1.5(97%) My Blog
Seetharaman Venkatasamy wrote:
shivendra tripathi wrote: But I never got the answer for "Why they have been introduced".
Vector is a legacy class . later sun introduced ArrayList which is replacement of Vector , but ArrayList is not synchronized , so they intoduced synchronizedList utility method to support Synchronization, since New classes shoudn't use Vector any more.
Seetharaman Venkatasam wrote:how ever CopyOnWriteArrayList is better thread-safe implementation of ArrayList