Class SafeLockImpl
java.lang.Object
com.pnfsoftware.jeb.util.concurrent.SafeLockImpl
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the underlying read-write lock.voidlock(boolean forWriting) Acquire either the read or write lock.voidlockRead()Acquire the read lock.voidAcquire the write lock.ro()Acquire an auto-closable read lock.rw()Acquire an auto-closable write lock.voidunlock(boolean forWriting) Release either the read or write lock.voidRelease a read lock held by the current thread.voidRelease the write lock held by the current thread.
-
Constructor Details
-
SafeLockImpl
public SafeLockImpl()Create a safe read-write lock.
-
-
Method Details
-
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
-
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
Acquire an auto-closable read lock. -
rw
Acquire an auto-closable write lock.
-