Class SafeLockImpl

java.lang.Object
com.pnfsoftware.jeb.util.concurrent.SafeLockImpl
All Implemented Interfaces:
ISafeLock

@Ser public class SafeLockImpl extends Object implements ISafeLock
Standard implementation of a safe lock, using a serializable reentrant read-write lock. It is highly recommended to use this lock through the safe interface ISafeLock. Direct use of non-auto-closable methods is not recommended.
See Also:
  • Constructor Details

    • SafeLockImpl

      public SafeLockImpl()
      Create a safe read-write lock.
  • Method Details

    • getInternalLock

      public ReentrantReadWriteLock getInternalLock()
      Get the underlying read-write lock.
      Returns:
      the internal lock
    • lockWrite

      public void lockWrite()
      Acquire the write lock.
      Throws:
      ConcurrentException - if the current thread is attempting an unsupported read-to-write lock upgrade
    • unlockWrite

      public void unlockWrite()
      Release the write lock held by the current thread.
    • lockRead

      public void lockRead()
      Acquire the read lock.
    • unlockRead

      public void unlockRead()
      Release a read lock held by the current thread.
    • debugFormatStatus

      public String debugFormatStatus()
    • lock

      public void lock(boolean forWriting)
      Acquire either the read or write lock.
      Parameters:
      forWriting - true to acquire the write lock; false to acquire the read lock
    • unlock

      public void unlock(boolean forWriting)
      Release either the read or write lock.
      Parameters:
      forWriting - true to release the write lock; false to release the read lock
    • ro

      public ACLock ro()
      Acquire an auto-closable read lock.
      Specified by:
      ro in interface ISafeLock
      Returns:
      an acquired read lock
    • rw

      public ACLock rw()
      Acquire an auto-closable write lock.
      Specified by:
      rw in interface ISafeLock
      Returns:
      an acquired write lock