public class

SynchronizedCollection

extends Object
implements Serializable Collection<E>
java.lang.Object
   ↳ org.apache.commons.collections.collection.SynchronizedCollection
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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.

Summary

Fields
protected final Collection collection The collection to decorate
protected final Object lock The object to lock on, needed for List/SortedSet views
Protected Constructors
SynchronizedCollection(Collection collection)
Constructor that wraps (not copies).
SynchronizedCollection(Collection collection, Object lock)
Constructor that wraps (not copies).
Public Methods
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()
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Iterable
From interface java.util.Collection

Fields

protected final Collection collection

The collection to decorate

protected final Object lock

The object to lock on, needed for List/SortedSet views

Protected Constructors

protected SynchronizedCollection (Collection collection)

Constructor that wraps (not copies).

Parameters
collection the collection to decorate, must not be null
Throws
IllegalArgumentException if the collection is null

protected SynchronizedCollection (Collection collection, Object lock)

Constructor that wraps (not copies).

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

Public Methods

public boolean add (Object object)

public boolean addAll (Collection coll)

public void clear ()

public boolean contains (Object object)

public boolean containsAll (Collection coll)

public static Collection decorate (Collection coll)

Factory method to create a synchronized collection.

Parameters
coll the collection to decorate, must not be null
Returns
  • a new synchronized collection
Throws
IllegalArgumentException if collection is null

public boolean equals (Object object)

public int hashCode ()

public boolean isEmpty ()

public Iterator iterator ()

Iterators must be manually synchronized.

 synchronized (coll) {
   Iterator it = coll.iterator();
   // do stuff with iterator
 }

Returns
  • an iterator that must be manually synchronized on the collection

public boolean remove (Object object)

public boolean removeAll (Collection coll)

public boolean retainAll (Collection coll)

public int size ()

public Object[] toArray ()

public Object[] toArray (Object[] object)

public String toString ()