D - generics reference, usually to <? extends DataSet>public class DefaultDataSetLock<D extends DataSet> extends Object implements DataSetLock<D>
writeLock()
and subsequent writeUnLock() mute and, respectively, un-mute the given DataSet's auto-notification
states, e.g. example:
lock.writeLock(); // stores isAutoNotification state
[..] some other code [..]
lock.writeUnLock(); // restores isAutoNotification state
However, the recommended usage is using the lock guard primitives, e.g.
lock.readLockGuard(() -> {
[..] some read-lock protected code [..]
return retVal; // N.B. optional return - here: assumes Objects or boxed primitives
});
Alternatively the best performing option for frequent simple reads without major data processing
Result ret = lock.readLockGuardOptimistic(() -> {
[..] some read-lock protected code [..]
return retVal; // N.B. optional return - here: assumes Objects or boxed primitives
});
The latter assumes infrequent writes (e.g. a single writer thread) and frequent unobstructed reads (ie. many reader
threads). The lock internally acquires the data w/o explicitly locking, checks afterwards if the data has potentially
changed a write-lock acquiring thread, and as a automatic fall-back uses the guaranteed (but more expensive) read
lock to assure that the read data structure is consistent.| Constructor and Description |
|---|
DefaultDataSetLock(D dataSet) |
| Modifier and Type | Method and Description |
|---|---|
D |
downGradeWriteLock()
Deprecated.
do not use (yet)
|
long |
getLastReadStamp() |
boolean |
getLastStoredAutoNotificationState() |
long |
getLastWriteStamp() |
StampedLock |
getLockObject() |
int |
getReaderCount() |
int |
getWriterCount() |
D |
readLock()
reentrant read-lock
|
D |
readLockGuard(Runnable reading) |
<R> R |
readLockGuard(Supplier<R> reading) |
D |
readLockGuardOptimistic(Runnable reading) |
<R> R |
readLockGuardOptimistic(Supplier<R> reading) |
D |
readUnLock() |
protected boolean |
threadsAreUnequal(Thread thread1,
Thread thread2) |
D |
writeLock() |
D |
writeLockGuard(Runnable writing) |
<R> R |
writeLockGuard(Supplier<R> writing) |
D |
writeUnLock() |
public DefaultDataSetLock(D dataSet)
dataSet - dataSet this set is associate with@Deprecated public D downGradeWriteLock()
public long getLastReadStamp()
StampedLockpublic boolean getLastStoredAutoNotificationState()
public long getLastWriteStamp()
StampedLockpublic StampedLock getLockObject()
public int getReaderCount()
public int getWriterCount()
public D readLock()
DataSetLockreadLock in interface DataSetLock<D extends DataSet>public D readLockGuard(Runnable reading)
readLockGuard in interface DataSetLock<D extends DataSet>reading - typ. lambda expression that is executed with read lockpublic <R> R readLockGuard(Supplier<R> reading)
readLockGuard in interface DataSetLock<D extends DataSet>R - generic return typereading - typ. lambda expression that is executed with read lockpublic D readLockGuardOptimistic(Runnable reading)
readLockGuardOptimistic in interface DataSetLock<D extends DataSet>reading - typ. lambda expression that is executed with read lockpublic <R> R readLockGuardOptimistic(Supplier<R> reading)
readLockGuardOptimistic in interface DataSetLock<D extends DataSet>R - generic return typereading - typ. lambda expression that is executed with read lockpublic D readUnLock()
readUnLock in interface DataSetLock<D extends DataSet>public D writeLock()
writeLock in interface DataSetLock<D extends DataSet>public D writeLockGuard(Runnable writing)
writeLockGuard in interface DataSetLock<D extends DataSet>writing - typ. lambda expression that is executed with write lockpublic <R> R writeLockGuard(Supplier<R> writing)
writeLockGuard in interface DataSetLock<D extends DataSet>R - generic return typewriting - typ. lambda expression that is executed with write lockpublic D writeUnLock()
writeUnLock in interface DataSetLock<D extends DataSet>Copyright © 2020 GSI Helmholtzzentrum für Schwerionenforschung GmbH. All rights reserved.