Class MCRReadWriteGuard

java.lang.Object
org.mycore.util.concurrent.MCRReadWriteGuard

public class MCRReadWriteGuard extends Object
A MCRReadWriteGuard acts like a ReadWriteLock but automatically wraps read and write operations accordingly.
Author:
Thomas Scheffler (yagee)
  • Constructor Details

    • MCRReadWriteGuard

      public MCRReadWriteGuard()
    • MCRReadWriteGuard

      public MCRReadWriteGuard(ReadWriteLock readWriteLock)
  • Method Details

    • read

      public <T> T read(Supplier<T> reader)
      Executes the read operation while the read lock is locked. This is a sharable lock. Many reader can be executed simultaneously when no write operation is running.
      Parameters:
      reader - a read operation that should be guarded.
      Returns:
      result of Supplier.get()
    • write

      public void write(Runnable operation)
      Executes the write operation while the write lock is locked. This is an exclusive lock. So no other read or write operation can be executed while operation is running.
      Parameters:
      operation -
    • lazyLoad

      public <T> T lazyLoad(Supplier<Boolean> check, Runnable operation, Supplier<T> reader)