public final class FunctionalReadWriteLock extends Object
ReentrantReadWriteLock
through a functional interfaceModifier and Type | Class and Description |
---|---|
static interface |
FunctionalReadWriteLock.LockReleaser
Functional interface for releasing a subject lock.
|
Modifier and Type | Method and Description |
---|---|
static FunctionalReadWriteLock |
readWriteLock()
Creates a new instance
|
<T> T |
withReadLock(CheckedFunction<FunctionalReadWriteLock.LockReleaser,T> function)
Executes the given function under the protection of the read lock and returns the output value.
|
void |
withWriteLock(CheckedRunnable runnable)
Executes the given supplier under the protection of the write lock.
|
<T> T |
withWriteLock(CheckedSupplier<T> supplier)
Executes the given supplier under the protection of the write lock and returns the
generated value.
|
public static FunctionalReadWriteLock readWriteLock()
public <T> T withReadLock(CheckedFunction<FunctionalReadWriteLock.LockReleaser,T> function)
The function receives a FunctionalReadWriteLock.LockReleaser
in order to release the read lock
in case a lock downgrade needs to be performed. If no downgrade is necessary, then there's
no need to manually release the lock.
T
- the generic type of the return valuefunction
- the protected functionpublic <T> T withWriteLock(CheckedSupplier<T> supplier)
T
- the generic type of the output valuesupplier
- a CheckedSupplier
public void withWriteLock(CheckedRunnable runnable)
runnable
- a CheckedRunnable
Copyright © 2018. All rights reserved.