Package dev.aherscu.qa.testing.extra
Class ReadMultiWriteLock
- java.lang.Object
-
- dev.aherscu.qa.testing.extra.ReadMultiWriteLock
-
public class ReadMultiWriteLock extends Object
Based on http://tutorials.jenkov.com/java-concurrency/read-write-locks.html#simpleAllows for multiple writers.
-
-
Constructor Summary
Constructors Constructor Description ReadMultiWriteLock()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
readingAquire()
Waits for writers to finish and accounts for another reader lock.void
readingRelease()
Accounts for one less reader lock.static void
readLocking(Runnable criticalSection)
Guards specified critical section for reading purposes.static <T> T
readLocking(Callable<T> criticalSection)
Guards specified critical section for reading purposes.static void
writeLocking(Runnable criticalSection)
Guards specified critical section for writing purposes.static <T> T
writeLocking(Callable<T> criticalSection)
Guards specified critical section for writing purposes.void
writingAcquire()
Waits for readers to finish and accounts for another writer lock.void
writingRelease()
Accounts for one less writer lock.
-
-
-
Method Detail
-
readLocking
public static <T> T readLocking(Callable<T> criticalSection)
Guards specified critical section for reading purposes.- Parameters:
criticalSection
- the critical section- Returns:
- value returned by critical section
-
readLocking
public static void readLocking(Runnable criticalSection)
Guards specified critical section for reading purposes.- Parameters:
criticalSection
- the critical section
-
writeLocking
public static <T> T writeLocking(Callable<T> criticalSection)
Guards specified critical section for writing purposes.- Parameters:
criticalSection
- the critical section- Returns:
- value returned by critical section
-
writeLocking
public static void writeLocking(Runnable criticalSection)
Guards specified critical section for writing purposes.- Parameters:
criticalSection
- the critical section
-
readingAquire
public void readingAquire() throws InterruptedException
Waits for writers to finish and accounts for another reader lock.- Throws:
InterruptedException
- if this thread was interrupted
-
readingRelease
public void readingRelease()
Accounts for one less reader lock.
-
writingAcquire
public void writingAcquire() throws InterruptedException
Waits for readers to finish and accounts for another writer lock.- Throws:
InterruptedException
- if this thread was interrupted
-
writingRelease
public void writingRelease()
Accounts for one less writer lock.
-
-