public class SimpleReadWriteLock extends ReentrantReadWriteLock
ReentrantReadWriteLock that allows for
easy usage with Java 8 :) See readLocked(Runnable) and
writeLocked(Runnable) method. For throwing versions see
readLockedThrowing(IThrowingRunnable) and
writeLockedThrowing(IThrowingRunnable). Also methods for callables
are available.ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock| Constructor and Description |
|---|
SimpleReadWriteLock()
Default constructor creating a default
ReentrantReadWriteLock |
SimpleReadWriteLock(boolean bFair)
Constructor creating a
ReentrantReadWriteLock with the provided
fairness |
| Modifier and Type | Method and Description |
|---|---|
void |
readLocked(Runnable aRunnable)
Execute the provided runnable in a read lock.
|
boolean |
readLockedBoolean(BooleanSupplier aSupplier)
Execute the provided callable in a read lock.
|
double |
readLockedDouble(DoubleSupplier aSupplier)
Execute the provided callable in a read lock.
|
<T> T |
readLockedGet(Supplier<? extends T> aSupplier)
Execute the provided callable in a read lock.
|
<T,EXTYPE extends Exception> |
readLockedGetThrowing(IThrowingSupplier<? extends T,EXTYPE> aCallable)
Execute the provided callable in a read lock.
|
int |
readLockedInt(IntSupplier aSupplier)
Execute the provided callable in a read lock.
|
long |
readLockedLong(LongSupplier aSupplier)
Execute the provided callable in a read lock.
|
<EXTYPE extends Exception> |
readLockedThrowing(IThrowingRunnable<EXTYPE> aRunnable)
Execute the provided runnable in a read lock.
|
void |
writeLocked(Runnable aRunnable)
Execute the provided runnable in a write lock.
|
boolean |
writeLockedBoolean(BooleanSupplier aSupplier)
Execute the provided callable in a write lock.
|
double |
writeLockedDouble(DoubleSupplier aSupplier)
Execute the provided callable in a write lock.
|
<T> T |
writeLockedGet(Supplier<? extends T> aSupplier)
Execute the provided callable in a write lock.
|
<T,EXTYPE extends Exception> |
writeLockedGetThrowing(IThrowingSupplier<? extends T,EXTYPE> aCallable)
Execute the provided callable in a write lock.
|
int |
writeLockedInt(IntSupplier aSupplier)
Execute the provided callable in a write lock.
|
long |
writeLockedLong(LongSupplier aSupplier)
Execute the provided callable in a write lock.
|
<EXTYPE extends Exception> |
writeLockedThrowing(IThrowingRunnable<EXTYPE> aRunnable)
Execute the provided runnable in a write lock.
|
getOwner, getQueuedReaderThreads, getQueuedThreads, getQueuedWriterThreads, getQueueLength, getReadHoldCount, getReadLockCount, getWaitingThreads, getWaitQueueLength, getWriteHoldCount, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isWriteLocked, isWriteLockedByCurrentThread, readLock, toString, writeLockpublic SimpleReadWriteLock()
ReentrantReadWriteLockpublic SimpleReadWriteLock(boolean bFair)
ReentrantReadWriteLock with the provided
fairnessbFair - true if this lock should use a fair ordering policypublic <T> T readLockedGet(@Nonnull Supplier<? extends T> aSupplier)
T - Return typeaSupplier - Callable to be executed. May not be null.null.public void readLocked(@Nonnull Runnable aRunnable)
aRunnable - Runnable to be executed. May not be null.public <EXTYPE extends Exception> void readLockedThrowing(@Nonnull IThrowingRunnable<EXTYPE> aRunnable) throws EXTYPE extends Exception
EXTYPE - Exception type to be thrownaRunnable - Runnable to be executed. May not be null.EXTYPE - If the callable throws the exceptionEXTYPE extends Exceptionpublic <T,EXTYPE extends Exception> T readLockedGetThrowing(@Nonnull IThrowingSupplier<? extends T,EXTYPE> aCallable) throws EXTYPE extends Exception
T - Return typeEXTYPE - Exception type to be thrownaCallable - Callable to be executed. May not be null.null.EXTYPE - If the callable throws the exceptionEXTYPE extends Exceptionpublic boolean readLockedBoolean(@Nonnull BooleanSupplier aSupplier)
aSupplier - Callable to be executed. May not be null.null.public double readLockedDouble(@Nonnull DoubleSupplier aSupplier)
aSupplier - Callable to be executed. May not be null.null.public int readLockedInt(@Nonnull IntSupplier aSupplier)
aSupplier - Callable to be executed. May not be null.null.public long readLockedLong(@Nonnull LongSupplier aSupplier)
aSupplier - Callable to be executed. May not be null.null.public void writeLocked(@Nonnull Runnable aRunnable)
aRunnable - Runnable to be executed. May not be null.public <EXTYPE extends Exception> void writeLockedThrowing(@Nonnull IThrowingRunnable<EXTYPE> aRunnable) throws EXTYPE extends Exception
EXTYPE - Exception type to be thrownaRunnable - Runnable to be executed. May not be null.EXTYPE - If the runnable throws the exceptionEXTYPE extends Exceptionpublic <T> T writeLockedGet(@Nonnull Supplier<? extends T> aSupplier)
T - Return typeaSupplier - Callable to be executed. May not be null.null.public <T,EXTYPE extends Exception> T writeLockedGetThrowing(@Nonnull IThrowingSupplier<? extends T,EXTYPE> aCallable) throws EXTYPE extends Exception
T - Return typeEXTYPE - Exception type to be thrownaCallable - Callable to be executed. May not be null.null.EXTYPE - If the callable throws the exceptionEXTYPE extends Exceptionpublic boolean writeLockedBoolean(@Nonnull BooleanSupplier aSupplier)
aSupplier - Callable to be executed. May not be null.null.public double writeLockedDouble(@Nonnull DoubleSupplier aSupplier)
aSupplier - Callable to be executed. May not be null.null.public int writeLockedInt(@Nonnull IntSupplier aSupplier)
aSupplier - Callable to be executed. May not be null.null.public long writeLockedLong(@Nonnull LongSupplier aSupplier)
aSupplier - Callable to be executed. May not be null.null.Copyright © 2014–2022 Philip Helger. All rights reserved.