JDK-4335520 : Provide access to Collections.synchronizedXXX(..., Object lock) variant
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 6
  • Priority: P5
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2000-05-03
  • Updated: 2017-05-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Related Reports
Duplicate :  
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) 

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang

WORK AROUND Name: skT45625 Date: 05/03/2000 Implement your own. Not a difficult chore, but its annoying (Especially given that a perfectly good implementation exists but its inaccessible) ======================================================================

EVALUATION When we initially provided the synchronized wrappers, we considered exporting the requested functionality, but decided to wait and see if there was any demand for the facility. joshua.bloch@Eng 2000-05-04 I now believe there is sufficient demand. ###@###.### 2002-04-26