Package com.helger.base.concurrent
Class SimpleReadWriteLock
java.lang.Object
java.util.concurrent.locks.ReentrantReadWriteLock
com.helger.base.concurrent.SimpleReadWriteLock
- All Implemented Interfaces:
Serializable,ReadWriteLock
This is an extension around
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.- Author:
- Philip Helger
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor creating a defaultReentrantReadWriteLockSimpleReadWriteLock(boolean bFair) Constructor creating aReentrantReadWriteLockwith the provided fairness -
Method Summary
Modifier and TypeMethodDescriptionvoidreadLocked(@NonNull Runnable aRunnable) Execute the provided runnable in a read lock.booleanreadLockedBoolean(@NonNull BooleanSupplier aSupplier) Execute the provided callable in a read lock.doublereadLockedDouble(@NonNull DoubleSupplier aSupplier) Execute the provided callable in a read lock.<T> TreadLockedGet(@NonNull Supplier<? extends T> aSupplier) Execute the provided callable in a read lock.<T,EXTYPE extends Exception>
TreadLockedGetThrowing(@NonNull IThrowingSupplier<? extends T, EXTYPE> aCallable) Execute the provided callable in a read lock.intreadLockedInt(@NonNull IntSupplier aSupplier) Execute the provided callable in a read lock.longreadLockedLong(@NonNull LongSupplier aSupplier) Execute the provided callable in a read lock.<EXTYPE extends Exception>
voidreadLockedThrowing(@NonNull IThrowingRunnable<EXTYPE> aRunnable) Execute the provided runnable in a read lock.voidwriteLocked(@NonNull Runnable aRunnable) Execute the provided runnable in a write lock.booleanwriteLockedBoolean(@NonNull BooleanSupplier aSupplier) Execute the provided callable in a write lock.doublewriteLockedDouble(@NonNull DoubleSupplier aSupplier) Execute the provided callable in a write lock.<T> TwriteLockedGet(@NonNull Supplier<? extends T> aSupplier) Execute the provided callable in a write lock.<T,EXTYPE extends Exception>
TwriteLockedGetThrowing(@NonNull IThrowingSupplier<? extends T, EXTYPE> aCallable) Execute the provided callable in a write lock.intwriteLockedInt(@NonNull IntSupplier aSupplier) Execute the provided callable in a write lock.longwriteLockedLong(@NonNull LongSupplier aSupplier) Execute the provided callable in a write lock.<EXTYPE extends Exception>
voidwriteLockedThrowing(@NonNull IThrowingRunnable<EXTYPE> aRunnable) Execute the provided runnable in a write lock.Methods inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
getOwner, getQueuedReaderThreads, getQueuedThreads, getQueuedWriterThreads, getQueueLength, getReadHoldCount, getReadLockCount, getWaitingThreads, getWaitQueueLength, getWriteHoldCount, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isWriteLocked, isWriteLockedByCurrentThread, readLock, toString, writeLock
-
Constructor Details
-
SimpleReadWriteLock
public SimpleReadWriteLock()Default constructor creating a defaultReentrantReadWriteLock -
SimpleReadWriteLock
public SimpleReadWriteLock(boolean bFair) Constructor creating aReentrantReadWriteLockwith the provided fairness- Parameters:
bFair-trueif this lock should use a fair ordering policy
-
-
Method Details
-
readLockedGet
Execute the provided callable in a read lock. Note: no nullable/non-nullable can be assumed.- Type Parameters:
T- Return type- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-
readLocked
Execute the provided runnable in a read lock.- Parameters:
aRunnable- Runnable to be executed. May not benull.
-
readLockedThrowing
public <EXTYPE extends Exception> void readLockedThrowing(@NonNull IThrowingRunnable<EXTYPE> aRunnable) throws EXTYPE Execute the provided runnable in a read lock.- Type Parameters:
EXTYPE- Exception type to be thrown- Parameters:
aRunnable- Runnable to be executed. May not benull.- Throws:
EXTYPE- If the callable throws the exception
-
readLockedGetThrowing
public <T,EXTYPE extends Exception> T readLockedGetThrowing(@NonNull IThrowingSupplier<? extends T, EXTYPE> aCallable) throws EXTYPEExecute the provided callable in a read lock. Note: no nullable/non-nullable can be assumed.- Type Parameters:
T- Return typeEXTYPE- Exception type to be thrown- Parameters:
aCallable- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null. - Throws:
EXTYPE- If the callable throws the exception
-
readLockedBoolean
Execute the provided callable in a read lock.- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-
readLockedDouble
Execute the provided callable in a read lock.- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-
readLockedInt
Execute the provided callable in a read lock.- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-
readLockedLong
Execute the provided callable in a read lock.- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-
writeLocked
Execute the provided runnable in a write lock.- Parameters:
aRunnable- Runnable to be executed. May not benull.
-
writeLockedThrowing
public <EXTYPE extends Exception> void writeLockedThrowing(@NonNull IThrowingRunnable<EXTYPE> aRunnable) throws EXTYPE Execute the provided runnable in a write lock.- Type Parameters:
EXTYPE- Exception type to be thrown- Parameters:
aRunnable- Runnable to be executed. May not benull.- Throws:
EXTYPE- If the runnable throws the exception
-
writeLockedGet
Execute the provided callable in a write lock. Note: no nullable/non-nullable can be assumed.- Type Parameters:
T- Return type- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-
writeLockedGetThrowing
public <T,EXTYPE extends Exception> T writeLockedGetThrowing(@NonNull IThrowingSupplier<? extends T, EXTYPE> aCallable) throws EXTYPEExecute the provided callable in a write lock. Note: no nullable/non-nullable can be assumed.- Type Parameters:
T- Return typeEXTYPE- Exception type to be thrown- Parameters:
aCallable- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null. - Throws:
EXTYPE- If the callable throws the exception
-
writeLockedBoolean
Execute the provided callable in a write lock.- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-
writeLockedDouble
Execute the provided callable in a write lock.- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-
writeLockedInt
Execute the provided callable in a write lock.- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-
writeLockedLong
Execute the provided callable in a write lock.- Parameters:
aSupplier- Callable to be executed. May not benull.- Returns:
- The return value of the callable. May be
null.
-