D - generics reference, usually to <? extends DataSet>public interface DataSetLock<D extends DataSet> extends Serializable
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.| Modifier and Type | Method and Description |
|---|---|
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() |
D |
writeLock() |
D |
writeLockGuard(Runnable writing) |
<R> R |
writeLockGuard(Supplier<R> writing) |
D |
writeUnLock() |
D readLock()
D readLockGuard(Runnable reading)
reading - typ. lambda expression that is executed with read lock<R> R readLockGuard(Supplier<R> reading)
R - generic return typereading - typ. lambda expression that is executed with read lockD readLockGuardOptimistic(Runnable reading)
reading - typ. lambda expression that is executed with read lock<R> R readLockGuardOptimistic(Supplier<R> reading)
R - generic return typereading - typ. lambda expression that is executed with read lockD readUnLock()
D writeLock()
D writeLockGuard(Runnable writing)
writing - typ. lambda expression that is executed with write lock<R> R writeLockGuard(Supplier<R> writing)
R - generic return typewriting - typ. lambda expression that is executed with write lockD writeUnLock()
Copyright © 2020 GSI Helmholtzzentrum für Schwerionenforschung GmbH. All rights reserved.