United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4335520 : Provide access to Collections.synchronizedXXX(..., Object lock) variant

Details
Type:
Enhancement
Submit Date:
2000-05-03
Status:
Open
Updated Date:
2014-07-22
Project Name:
JDK
Resolved Date:
Component:
core-libs
OS:
generic
Sub-Component:
java.util:collections
CPU:
generic
Priority:
P5
Resolution:
Unresolved
Affected Versions:
6
Targeted Versions:
tbd_major

Related Reports
Duplicate:

Sub Tasks

Description
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) 
======================================================================

                                    

Comments
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
                                     
2000-05-04
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)
======================================================================
                                     
2004-09-08
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mustang


                                     
2004-09-08



Hardware and Software, Engineered to Work Together