Class ReadMultiWriteLock


  • public class ReadMultiWriteLock
    extends Object
    Based on http://tutorials.jenkov.com/java-concurrency/read-write-locks.html#simple

    Allows for multiple writers.

    • Constructor Detail

      • ReadMultiWriteLock

        public ReadMultiWriteLock()
    • 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.