Name: skT45625 Date: 05/03/2000
java version "1.2.2"
Classic VM (build JDK-1.2.2-001, native threads, nojit)
I would like to see the following methods added to the java.util.Collections
utility class:
public static Collection synchronizedCollection(Collection c, Object lock);
public static List synchronizedList(List l, Object lock);
public static Set synchronizedSet(Set s, Object lock);
public static Map synchronizedMap(Map m, Object lock);
public static SortedSet synchronizedSortedSet(SortedSet ss, Object lock);
public static SortedMap synchronizedSortedMap(SortedMap sm, Object lock);
Each of these methods would return a wrapper around the given collection which
synchronizes all access on the given lock object (which must not be null). This
would allow more flexibility than the current versions of these methods. In
particular, it would be possible for a bean to expose a List (or Set, or Map,
etc.) view of some internal data that is synchronized on the bean itself,
instead of the wrapper. For example:
public class Wombat {
private List internalList = ..;
public List getInternalList() {
// the returned list is synchronized on the wombat that owns it
return Collections.synchronizedList(internalList, this);
}
}
NOTE: The implementation for these methods is already in place so providing
these methods should be fairly simple.
(Review ID: 104421)
======================================================================