org.apache.commons.collections.collection
public class SynchronizedCollection extends Object implements Collection, Serializable
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.
Since: Commons Collections 3.0
Version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
Field Summary | |
---|---|
protected Collection | collection The collection to decorate |
protected Object | lock The object to lock on, needed for List/SortedSet views |
Constructor Summary | |
---|---|
protected | SynchronizedCollection(Collection collection)
Constructor that wraps (not copies).
|
protected | SynchronizedCollection(Collection collection, Object lock)
Constructor that wraps (not copies).
|
Method Summary | |
---|---|
boolean | add(Object object) |
boolean | addAll(Collection coll) |
void | clear() |
boolean | contains(Object object) |
boolean | containsAll(Collection coll) |
static Collection | decorate(Collection coll)
Factory method to create a synchronized collection.
|
boolean | equals(Object object) |
int | hashCode() |
boolean | isEmpty() |
Iterator | iterator()
Iterators must be manually synchronized.
|
boolean | remove(Object object) |
boolean | removeAll(Collection coll) |
boolean | retainAll(Collection coll) |
int | size() |
Object[] | toArray() |
Object[] | toArray(Object[] object) |
String | toString() |
Parameters: collection the collection to decorate, must not be null
Throws: IllegalArgumentException if the collection is null
Parameters: collection the collection to decorate, must not be null lock the lock object to use, must not be null
Throws: IllegalArgumentException if the collection is null
Parameters: coll the collection to decorate, must not be null
Returns: a new synchronized collection
Throws: IllegalArgumentException if collection is null
synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator }Returns: an iterator that must be manually synchronized on the collection