Class MultiReaderHashBag<T>

All Implemented Interfaces:
Externalizable, Serializable, Iterable<T>, Collection<T>, Bag<T>, MultiReaderBag<T>, MutableBag<T>, MutableBagIterable<T>, UnsortedBag<T>, MutableCollection<T>, InternalIterable<T>, RichIterable<T>

public final class MultiReaderHashBag<T>
extends AbstractMultiReaderMutableCollection<T>
implements Externalizable, MultiReaderBag<T>
MultiReaderHashBag provides a thread-safe wrapper around a HashBag, using a ReentrantReadWriteLock. In order to provide true thread-safety, MultiReaderHashBag does not implement iterator() as this method requires an external lock to be taken to provide thread-safe iteration. All of these methods are available however, if you use the withReadLockAndDelegate() or withWriteLockAndDelegate() methods. Both of these methods take a parameter of type Procedure<MutableBag>, and a wrapped version of the underlying HashBag is returned. This wrapper guarantees that no external pointer can ever reference the underlying HashBag outside of a locked procedure. In the case of the read lock method, an Unmodifiable version of the collection is offered, which will throw UnsupportedOperationExceptions on any write methods like add or remove.
See Also:
Serialized Form