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, SynchronizedBag.SynchronizedBagSet, SynchronizedMultiSet, SynchronizedMultiSet.SynchronizedSet, SynchronizedQueue

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
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization version
      See Also:
    • collection

      private final Collection<E> 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<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