Class SynchronizedCollection

java.lang.Object
org.apache.commons.collections.collection.SynchronizedCollection
All Implemented Interfaces:
Serializable, Iterable, Collection
Direct Known Subclasses:
SynchronizedBag, SynchronizedBuffer, SynchronizedList, SynchronizedSet, SynchronizedSortedSet

public class SynchronizedCollection extends 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.

Since:
Commons Collections 3.0
Version:
$Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
Author:
Stephen Colebourne
See Also:
  • Field Details

    • collection

      protected final Collection collection
      The collection to decorate
    • lock

      protected final Object lock
      The object to lock on, needed for List/SortedSet views
  • Constructor Details

    • SynchronizedCollection

      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
    • SynchronizedCollection

      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
  • Method Details