com.jthreadkit.collection
Class WrappedSizeMonitoredList
java.lang.Object
|
+--com.jthreadkit.AbstractSizeMonitored
|
+--com.jthreadkit.collection.WrappedSizeMonitoredCollection
|
+--com.jthreadkit.collection.WrappedSizeMonitoredList
- All Implemented Interfaces:
- AccessibleLock, Collection, List, SimpleShutdown, SizeMonitored, SizeMonitoredCollection, SizeMonitoredList, TimedOutExceptionOption
- public class WrappedSizeMonitoredList
- extends WrappedSizeMonitoredCollection
- implements SizeMonitoredList, List, SizeMonitored
Used to wrap an instance of List with synchronization
and implementation of all the methods of SizeMonitored.
This class can be used like this:
|
SizeMonitoredList sml =
new WrappedSizeMonitoredList(new ArrayList());
SizeMonitored sm = sml; // can be viewed as a SizeMonitored
List list = sml; // can be viewed as a List too
|
Note that when possible it's best to avoid keeping a direct reference to
the underlying "raw" List (like this example above). This
makes accidental use of the un-synchronized one impossible.
All method calls are synchronized on the object returned
by getLockObject().
The object to lock on can be specified during construction
or defaults to this. [There is no
need to wrap the raw or resulting wrapped object by using
Collections.synchronizedList().]
To safely iterate in an multithreaded environment, use code like this:
|
SizeMonitoredList sml = //...
//...
synchronized ( sml.getLockObject() ) {
Iterator iter = sml.iterator();
while ( iter.hasNext() ) {
Object obj = iter.next();
//...
}
}
|
The methods of SizeMonitored are nicely combined so that
we can have one thread doing something like this:
while another thread is modifying (adding and removing elements) the
object.
| Methods inherited from class com.jthreadkit.collection.WrappedSizeMonitoredCollection |
add, addAll, clear, contains, containsAll, equals, hashCode, iterator, remove, removeAll, retainAll, setCapacity, size, toArray, toArray |
| Methods inherited from class com.jthreadkit.AbstractSizeMonitored |
addSizeChangeListener, getCapacity, getLockObject, getSize, isEmpty, isFull, isUseTimedOutExceptionSet, removeSizeChangeListener, setUseTimedOutException, shutdown, shutdownWhenEmpty, waitForSizeToChange, waitForSizeToChange, waitForSizeToClimbTo, waitForSizeToClimbTo, waitForSizeToFallTo, waitForSizeToFallTo, waitUntilEmpty, waitUntilEmpty, waitUntilFull, waitUntilFull, waitUntilSizeInRange, waitUntilSizeInRange, waitUntilSizeIs, waitUntilSizeIs, waitWhileEmpty, waitWhileEmpty, waitWhileFull, waitWhileFull, waitWhileSizeInRange, waitWhileSizeInRange, waitWhileSizeIs, waitWhileSizeIs |
| Methods inherited from interface com.jthreadkit.SizeMonitored |
addSizeChangeListener, getCapacity, getSize, isEmpty, isFull, removeSizeChangeListener, setCapacity, shutdownWhenEmpty, waitForSizeToChange, waitForSizeToChange, waitForSizeToClimbTo, waitForSizeToClimbTo, waitForSizeToFallTo, waitForSizeToFallTo, waitUntilEmpty, waitUntilEmpty, waitUntilFull, waitUntilFull, waitUntilSizeInRange, waitUntilSizeInRange, waitUntilSizeIs, waitUntilSizeIs, waitWhileEmpty, waitWhileEmpty, waitWhileFull, waitWhileFull, waitWhileSizeInRange, waitWhileSizeInRange, waitWhileSizeIs, waitWhileSizeIs |
| Methods inherited from interface java.util.List |
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
WrappedSizeMonitoredList
public WrappedSizeMonitoredList(List list,
Object lock,
boolean useTimedOutException)
WrappedSizeMonitoredList
public WrappedSizeMonitoredList(List list)
add
public void add(int index,
Object o)
throws ShutdownException
- Specified by:
add in interface List
addAll
public boolean addAll(int index,
Collection c)
throws ShutdownException
- Specified by:
addAll in interface List
get
public Object get(int index)
- Specified by:
get in interface List
indexOf
public int indexOf(Object o)
- Specified by:
indexOf in interface List
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOf in interface List
listIterator
public ListIterator listIterator()
- Specified by:
listIterator in interface List
listIterator
public ListIterator listIterator(int index)
- Specified by:
listIterator in interface List
remove
public Object remove(int index)
throws ShutdownException
- Specified by:
remove in interface List
set
public Object set(int index,
Object o)
throws ShutdownException
- Specified by:
set in interface List
subList
public List subList(int fromIndex,
int toIndex)
- Specified by:
subList in interface List
© Copyright 2000-2001 Programix Incorporated. All rights reserved. JThreadKit home