I would sort of disagree with that.
Synchronization has been removed in the JDK 1.2 collections because it usually is just extra overhead that doesn't buy you anything:
In single-threaded code, you don't need synchronization.In multi-threaded code, you usually do need synchronization, but rarely where Hashtable, Vector and friends provide it. Most of the time, it is not the little collection methods that need to be atomic with respect to other threads, but much coarser-grained operations that you write yourself. The synchronization in Hashtable etc. is then useless, and worse, it may lull inexperienced developers into a false sense of security: their code "is threadsafe because it uses synchronized collections". Not at all.Secondly, I disagree that you would use Hashtable if you
did happen to need a map that was synchronized at that level; use Collections.synchronizedMap(). Hashtable, like all the legacy collection classes such as Vector, should be avoided where possible for their synchronization, bloated API, and inferior enumeration behaviour.
See also
this thread.
- Peter