Package com.helger.commons.concurrent
Class SimpleReadWriteLock
java.lang.Object
java.util.concurrent.locks.ReentrantReadWriteLock
com.helger.commons.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(Runnable aRunnable) Execute the provided runnable in a read lock.booleanreadLockedBoolean(BooleanSupplier aSupplier) Execute the provided callable in a read lock.doublereadLockedDouble(DoubleSupplier aSupplier) Execute the provided callable in a read lock.<T> TreadLockedGet(Supplier<? extends T> aSupplier) Execute the provided callable in a read lock.<T,EXTYPE extends Exception>
TreadLockedGetThrowing(IThrowingSupplier<? extends T, EXTYPE> aCallable) Execute the provided callable in a read lock.intreadLockedInt(IntSupplier aSupplier) Execute the provided callable in a read lock.longreadLockedLong(LongSupplier aSupplier) Execute the provided callable in a read lock.<EXTYPE extends Exception>
voidreadLockedThrowing(IThrowingRunnable<EXTYPE> aRunnable) Execute the provided runnable in a read lock.voidwriteLocked(Runnable aRunnable) Execute the provided runnable in a write lock.booleanwriteLockedBoolean(BooleanSupplier aSupplier) Execute the provided callable in a write lock.doublewriteLockedDouble(DoubleSupplier aSupplier) Execute the provided callable in a write lock.<T> TwriteLockedGet(Supplier<? extends T> aSupplier) Execute the provided callable in a write lock.<T,EXTYPE extends Exception>
TwriteLockedGetThrowing(IThrowingSupplier<? extends T, EXTYPE> aCallable) Execute the provided callable in a write lock.intwriteLockedInt(IntSupplier aSupplier) Execute the provided callable in a write lock.longwriteLockedLong(LongSupplier aSupplier) Execute the provided callable in a write lock.<EXTYPE extends Exception>
voidwriteLockedThrowing(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.
-