Package EDU.oswego.cs.dl.util.concurrent
Class SyncMap
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.SyncMap
- All Implemented Interfaces:
Map
- Direct Known Subclasses:
SyncSortedMap
SyncMaps wrap Sync-based control around java.util.Maps.
They operate in the same way as SyncCollection.
Reader operations are
- size
- isEmpty
- get
- containsKey
- containsValue
- keySet
- entrySet
- values
- put
- putAll
- remove
- clear
- See Also:
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map
protected final Sync
protected final SynchronizedLong
protected final Sync
-
Constructor Summary
ConstructorsConstructorDescriptionSyncMap
(Map map, ReadWriteLock rwl) Create a new SyncMap protecting the given map, and using the given ReadWriteLock to control reader and writer methods.Create a new SyncMap protecting the given map, and using the given sync to control both reader and writer methods.Create a new SyncMap protecting the given map, and using the given pair of locks to control reader and writer methods. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
afterRead
(boolean wasInterrupted) Clean up after a reader operationprotected boolean
Try to acquire sync before a reader operation; record failurevoid
clear()
boolean
boolean
entrySet()
boolean
int
hashCode()
boolean
isEmpty()
keySet()
void
Return the Sync object managing read-only operationsint
size()
long
Return the number of synchronization failures for read-only operationsvalues()
Return the Sync object managing mutative operationsMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
c_
-
rd_
-
wr_
-
syncFailures_
-
-
Constructor Details
-
SyncMap
Create a new SyncMap protecting the given map, and using the given sync to control both reader and writer methods. Common, reasonable choices for the sync argument include Mutex, ReentrantLock, and Semaphores initialized to 1. -
SyncMap
Create a new SyncMap protecting the given map, and using the given ReadWriteLock to control reader and writer methods. -
SyncMap
Create a new SyncMap protecting the given map, and using the given pair of locks to control reader and writer methods.
-
-
Method Details
-
readerSync
Return the Sync object managing read-only operations -
writerSync
Return the Sync object managing mutative operations -
syncFailures
public long syncFailures()Return the number of synchronization failures for read-only operations -
beforeRead
protected boolean beforeRead()Try to acquire sync before a reader operation; record failure -
afterRead
protected void afterRead(boolean wasInterrupted) Clean up after a reader operation -
hashCode
public int hashCode() -
equals
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap
-
containsValue
- Specified by:
containsValue
in interfaceMap
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
entrySet
-
values
-