Class SynchronizedCollection<E>

java.lang.Object
org.apache.commons.collections4.collection.SynchronizedCollection<E>
Type Parameters:
E - the type of the elements in the collection
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>
Direct Known Subclasses:
SynchronizedBag, SynchronizedMultiSet

public class SynchronizedCollection<E> extends Object implements Collection<E>, 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:
3.0
Version:
$Id: SynchronizedCollection.java 1686855 2015-06-22 13:00:27Z tn $
See Also:
  • Field Details

    • lock

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

    • SynchronizedCollection

      protected SynchronizedCollection(Collection<E> collection)
      Constructor that wraps (not copies).
      Parameters:
      collection - the collection to decorate, must not be null
      Throws:
      NullPointerException - if the collection is null
    • SynchronizedCollection

      protected SynchronizedCollection(Collection<E> 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:
      NullPointerException - if the collection or lock is null
  • Method Details