InterviewSolution
| 1. |
How Can We Synchronize A Collection Or How To Make A Collection Thread-safe? |
|
Answer» Collections class has several STATIC methods that RETURN synchronized collections. Each of the six core collection interfaces -Collection, SET, List, Map, SortedSet, and SortedMap - has one static factory method. public static <T> Collection<T> synchronizedCollection(Collection<T> c); Each of these methods returns a synchronized (thread-safe) Collection backed up by the specified collection. Collections class has several static methods that return synchronized collections. Each of the six core collection interfaces -Collection, Set, List, Map, SortedSet, and SortedMap - has one static factory method. public static <T> Collection<T> synchronizedCollection(Collection<T> c); Each of these methods returns a synchronized (thread-safe) Collection backed up by the specified collection. |
|