Class ReadWriteLock

java.lang.Object
com.aquima.interactions.foundation.utility.ReadWriteLock

public class ReadWriteLock extends Object
Read-write mutex implementation that can be used to allow concurrent reads, but single threaded writes.

This implementation of ReadWriteLock will give preference to the waiting writer threads over the readers, through the waitingWriters variable. That means if we have two threads waiting to acquire the lock, the one waiting for write lock will get the lock first.

Since:
6.3
Author:
O. Kerpershoek
  • Constructor Details

    • ReadWriteLock

      public ReadWriteLock(String identifier)
      Constructs the read-write lock.
      Parameters:
      identifier - identifier for the class acquiring the lock
  • Method Details

    • getReadLock

      public void getReadLock()
      This method should be invoked to acquire a read lock. The method will block until a read lock is available. As soon as the read lock is no longer required, the releaseReadLock method should be invoked.
    • getWriteLock

      public void getWriteLock()
      This method should be invoked to acquire a write lock. The method will block until a write lock is available. As soon as the write lock is no longer required, the releaseWriteLock method should be invoked.
    • releaseReadLock

      public void releaseReadLock()
      This method should be invoked to release a read lock.
    • releaseWriteLock

      public void releaseWriteLock()
      This method should be invoked to release a write lock.