Legacy synchronized collections to modern alternatives
Replace Vector and Hashtable with collections selected for actual mutability and concurrency needs.
Code Comparison
✕ Legacy synchronized collection
Hashtable<String, Session> sessions = new Hashtable<>(); sessions.put(id, session);
✓ Concurrent Collections API
ConcurrentMap<String, Session> sessions = new ConcurrentHashMap<>(); sessions.put(id, session);
See a problem with this code? Let us know.
Why the modern way wins
Intentional concurrency
The chosen type documents whether sharing is expected.
Better scalability
ConcurrentHashMap avoids a single table-wide lock for normal access.
Modern APIs
Works naturally with current collection and concurrent-map operations.
Old Approach
Hashtable
Modern Approach
ConcurrentHashMap
Since JDK
5
Difficulty
Intermediate
JDK Support
Legacy synchronized collections to modern alternatives
Available
Widely available since JDK 5 (September 2004)
How it works
Vector and Hashtable synchronize every operation through legacy APIs. Modern code should normally use ArrayList or HashMap for thread-confined data, and purpose-built concurrent collections when shared mutation is required.
Related Documentation
Proof