org.apache.commons.collections.collection
Class SynchronizedCollection
java.lang.Object
org.apache.commons.collections.collection.SynchronizedCollection
- Collection, Serializable
public class SynchronizedCollection
extends java.lang.Object
implements Collection, Serializable
Decorates another
Collection
to synchronize its behaviour
for a multi-threaded environment.
Iterators must be manually synchronized:
synchronized (coll) {
Iterator it = coll.iterator();
// do stuff with iterator
}
This class is Serializable from Commons Collections 3.1.
$Revision: 1.7 $ $Date: 2004/06/03 22:02:13 $protected Collection | collection - The collection to decorate
|
protected Object | lock - The object to lock on, needed for List/SortedSet views
|
collection
protected final Collection collection
The collection to decorate
lock
protected final Object lock
The object to lock on, needed for List/SortedSet views
SynchronizedCollection
protected SynchronizedCollection(Collection collection)
Constructor that wraps (not copies).
collection
- the collection to decorate, must not be null
SynchronizedCollection
protected SynchronizedCollection(Collection collection,
Object lock)
Constructor that wraps (not copies).
collection
- the collection to decorate, must not be nulllock
- the lock object to use, must not be null
add
public boolean add(Object object)
addAll
public boolean addAll(Collection coll)
contains
public boolean contains(Object object)
containsAll
public boolean containsAll(Collection coll)
decorate
public static Collection decorate(Collection coll)
Factory method to create a synchronized collection.
coll
- the collection to decorate, must not be null
- a new synchronized collection
equals
public boolean equals(Object object)
hashCode
public int hashCode()
isEmpty
public boolean isEmpty()
iterator
public Iterator iterator()
Iterators must be manually synchronized.
synchronized (coll) {
Iterator it = coll.iterator();
// do stuff with iterator
}
- an iterator that must be manually synchronized on the collection
remove
public boolean remove(Object object)
removeAll
public boolean removeAll(Collection coll)
retainAll
public boolean retainAll(Collection coll)
toArray
public Object[] toArray()
toArray
public Object[] toArray(Object[] object)
toString
public String toString()
Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.