Best practices in Collections

If you do need a synchronized map, you can use the static method synchronizedMap(…) in class Collections to add synchronization to a regular map. Don’t use the legacy collection classes, such as Hashtable. Example:

// A regular, unsynchronized map  
Map map = new HashMap();

// Wrap it to add synchronization
Map synchedMap = Collections.synchronizedMap(map);

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.