E - the type of the elements in the collection
public class SynchronizedCollection<E> extends Objectimplements Collection <E>, Serializable
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.
| Modifier and Type | Field and Description |
|---|---|
protected Object |
lock
The object to lock on, needed for List/SortedSet views
|
| Modifier | Constructor and Description |
|---|---|
protected |
SynchronizedCollection(Collection
Constructor that wraps (not copies).
|
protected |
SynchronizedCollection(Collection
Constructor that wraps (not copies).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E object)
|
boolean |
addAll(Collection
|
void |
clear()
|
boolean |
contains(Object
|
boolean |
containsAll(Collection
|
protected Collection |
decorated()
Gets the collection being decorated.
|
boolean |
equals(Object
|
int |
hashCode()
|
boolean |
isEmpty()
|
Iterator |
iterator()
Iterators must be manually synchronized.
|
boolean |
remove(Object
|
boolean |
removeAll(Collection
|
boolean |
retainAll(Collection
|
int |
size()
|
static <T> SynchronizedCollection |
synchronizedCollection(Collection
Factory method to create a synchronized collection.
|
Object |
toArray()
|
<T> T[] |
toArray(T[] object)
|
String |
toString()
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitparallelStream, removeIf, spliterator, streamprotected final Objectlock
protected SynchronizedCollection(Collection<E> collection)
collection - the collection to decorate, must not be null
NullPointerException - if the collection is null
protected SynchronizedCollection(Collection<E> collection, Object lock)
collection - the collection to decorate, must not be null
lock - the lock object to use, must not be null
NullPointerException - if the collection or lock is null
public static <T> SynchronizedCollection<T> synchronizedCollection(Collection <T> coll)
T - the type of the elements in the collection
coll - the collection to decorate, must not be null
NullPointerException - if collection is null
protected Collection<E> decorated()
public boolean add(E object)
public boolean addAll(Collection<? extends E> coll)
public void clear()
public boolean contains(Objectobject)
public boolean containsAll(Collection<?> coll)
public boolean isEmpty()
public Iterator<E> iterator()
synchronized (coll) {
Iterator it = coll.iterator();
// do stuff with iterator
}
public Object[] toArray()
public <T> T[] toArray(T[] object)
public boolean remove(Objectobject)
public boolean removeAll(Collection<?> coll)
public boolean retainAll(Collection<?> coll)
public int size()
public boolean equals(Objectobject)
public int hashCode()
public StringtoString()