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
public class SimpleReadWriteLock extends ReentrantReadWriteLock
This is an extension aroundReentrantReadWriteLockthat allows for easy usage with Java 8 :) SeereadLocked(Runnable)andwriteLocked(Runnable)method. For throwing versions seereadLockedThrowing(IThrowingRunnable)andwriteLockedThrowing(IThrowingRunnable). Also methods for callables are available.- Author:
- Philip Helger
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock
-
-
Constructor Summary
Constructors Constructor Description SimpleReadWriteLock()Default constructor creating a defaultReentrantReadWriteLockSimpleReadWriteLock(boolean bFair)Constructor creating aReentrantReadWriteLockwith the provided fairness
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidreadLocked(Runnable aRunnable)Execute the provided runnable in a read lock.booleanreadLocked(BooleanSupplier aSupplier)Deprecated.Since 9.4.0; UsereadLockedBoolean(BooleanSupplier)insteaddoublereadLocked(DoubleSupplier aSupplier)Deprecated.Since 9.4.0; UsereadLockedDouble(DoubleSupplier)insteadintreadLocked(IntSupplier aSupplier)Deprecated.Since 9.4.0; UsereadLockedInt(IntSupplier)insteadlongreadLocked(LongSupplier aSupplier)Deprecated.Since 9.4.0; UsereadLockedLong(LongSupplier)instead<T> TreadLocked(Supplier<? extends T> aSupplier)Deprecated.Since 9.4.0; UsereadLockedGet(Supplier)insteadbooleanreadLockedBoolean(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.<T,EXTYPE extends Exception>
TreadLockedThrowing(IThrowingSupplier<? extends T,EXTYPE> aCallable)Deprecated.Since 9.4.0; UsereadLockedGetThrowing(IThrowingSupplier)insteadvoidwriteLocked(Runnable aRunnable)Execute the provided runnable in a write lock.booleanwriteLocked(BooleanSupplier aSupplier)Deprecated.Since 9.4.0; UsewriteLockedBoolean(BooleanSupplier)insteaddoublewriteLocked(DoubleSupplier aSupplier)Deprecated.Since 9.4.0; UsewriteLockedDouble(DoubleSupplier)insteadintwriteLocked(IntSupplier aSupplier)Deprecated.Since 9.4.0; UsewriteLockedInt(IntSupplier)insteadlongwriteLocked(LongSupplier aSupplier)Deprecated.Since 9.4.0; UsewriteLockedLong(LongSupplier)instead<T> TwriteLocked(Supplier<? extends T> aSupplier)Deprecated.Since 9.4.0; UsewriteLockedGet(Supplier)insteadbooleanwriteLockedBoolean(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.<T,EXTYPE extends Exception>
TwriteLockedThrowing(IThrowingSupplier<? extends T,EXTYPE> aCallable)Deprecated.Since 9.4.0; UsewriteLockedGetThrowing(IThrowingSupplier)instead-
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 Detail
-
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 Detail
-
readLocked
@Deprecated public <T> T readLocked(@Nonnull Supplier<? extends T> aSupplier)
Deprecated.Since 9.4.0; UsereadLockedGet(Supplier)insteadExecute 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.
-
readLockedGet
public <T> T readLockedGet(@Nonnull Supplier<? extends T> aSupplier)
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
public void readLocked(@Nonnull Runnable aRunnable)
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 extends Exception
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 exceptionEXTYPE extends Exception
-
readLockedThrowing
@Deprecated public <T,EXTYPE extends Exception> T readLockedThrowing(@Nonnull IThrowingSupplier<? extends T,EXTYPE> aCallable) throws EXTYPE extends Exception
Deprecated.Since 9.4.0; UsereadLockedGetThrowing(IThrowingSupplier)insteadExecute 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 exceptionEXTYPE extends Exception
-
readLockedGetThrowing
public <T,EXTYPE extends Exception> T readLockedGetThrowing(@Nonnull IThrowingSupplier<? extends T,EXTYPE> aCallable) throws EXTYPE extends Exception
Execute 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 exceptionEXTYPE extends Exception
-
readLocked
@Deprecated public boolean readLocked(@Nonnull BooleanSupplier aSupplier)
Deprecated.Since 9.4.0; UsereadLockedBoolean(BooleanSupplier)insteadExecute 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.
-
readLockedBoolean
public boolean readLockedBoolean(@Nonnull BooleanSupplier aSupplier)
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.
-
readLocked
@Deprecated public double readLocked(@Nonnull DoubleSupplier aSupplier)
Deprecated.Since 9.4.0; UsereadLockedDouble(DoubleSupplier)insteadExecute 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
public double readLockedDouble(@Nonnull DoubleSupplier aSupplier)
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.
-
readLocked
@Deprecated public int readLocked(@Nonnull IntSupplier aSupplier)
Deprecated.Since 9.4.0; UsereadLockedInt(IntSupplier)insteadExecute 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
public int readLockedInt(@Nonnull IntSupplier aSupplier)
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.
-
readLocked
@Deprecated public long readLocked(@Nonnull LongSupplier aSupplier)
Deprecated.Since 9.4.0; UsereadLockedLong(LongSupplier)insteadExecute 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
public long readLockedLong(@Nonnull LongSupplier aSupplier)
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
public void writeLocked(@Nonnull Runnable aRunnable)
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 extends Exception
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 exceptionEXTYPE extends Exception
-
writeLocked
@Deprecated public <T> T writeLocked(@Nonnull Supplier<? extends T> aSupplier)
Deprecated.Since 9.4.0; UsewriteLockedGet(Supplier)insteadExecute 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.
-
writeLockedGet
public <T> T writeLockedGet(@Nonnull Supplier<? extends T> aSupplier)
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.
-
writeLockedThrowing
@Deprecated public <T,EXTYPE extends Exception> T writeLockedThrowing(@Nonnull IThrowingSupplier<? extends T,EXTYPE> aCallable) throws EXTYPE extends Exception
Deprecated.Since 9.4.0; UsewriteLockedGetThrowing(IThrowingSupplier)insteadExecute 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 exceptionEXTYPE extends Exception
-
writeLockedGetThrowing
public <T,EXTYPE extends Exception> T writeLockedGetThrowing(@Nonnull IThrowingSupplier<? extends T,EXTYPE> aCallable) throws EXTYPE extends Exception
Execute 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 exceptionEXTYPE extends Exception
-
writeLocked
@Deprecated public boolean writeLocked(@Nonnull BooleanSupplier aSupplier)
Deprecated.Since 9.4.0; UsewriteLockedBoolean(BooleanSupplier)insteadExecute 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.
-
writeLockedBoolean
public boolean writeLockedBoolean(@Nonnull BooleanSupplier aSupplier)
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.
-
writeLocked
@Deprecated public double writeLocked(@Nonnull DoubleSupplier aSupplier)
Deprecated.Since 9.4.0; UsewriteLockedDouble(DoubleSupplier)insteadExecute 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
public double writeLockedDouble(@Nonnull DoubleSupplier aSupplier)
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.
-
writeLocked
@Deprecated public int writeLocked(@Nonnull IntSupplier aSupplier)
Deprecated.Since 9.4.0; UsewriteLockedInt(IntSupplier)insteadExecute 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
public int writeLockedInt(@Nonnull IntSupplier aSupplier)
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.
-
writeLocked
@Deprecated public long writeLocked(@Nonnull LongSupplier aSupplier)
Deprecated.Since 9.4.0; UsewriteLockedLong(LongSupplier)insteadExecute 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
public long writeLockedLong(@Nonnull LongSupplier aSupplier)
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.
-
-