public interface Lock
A
Lock on a Lockable resource is either
a read lock or an exclusive write lock. It is acquired indirectly by one of
the execute methods in Lockable.- Author:
- Ole Kniemeyer
-
Method Summary
Modifier and TypeMethodDescriptionvoidexecuteWithoutWriteLock(Runnable callback) Executescallbackwhile temporarily reducing this write lock to a read lock.Returns the resource on which this lock is held.booleanReturns the type of lock.voidretain()A lock may be retained by invocation of this method within theLockProtectedRunnable.run(boolean, Lock)method of a task.
-
Method Details
-
getLockable
Lockable getLockable()Returns the resource on which this lock is held.- Returns:
- resource locked by this lock
-
retain
void retain()A lock may be retained by invocation of this method within theLockProtectedRunnable.run(boolean, Lock)method of a task. In this case, the lock is not released after the task has been finished: The lock remains active and has to be passed to one of theexecutemethods inLockablewhich take a lock as parameter, only then the lock will be released. -
executeWithoutWriteLock
Executescallbackwhile temporarily reducing this write lock to a read lock. This gives threads waiting for a read lock the chance to execute.- Throws:
IllegalStateException- if this lock is not a write lockInterruptedException- if this thread is interrupted while reacquiring the write lock. In this case the lock stays a read lock
-
isWriteLock
boolean isWriteLock()Returns the type of lock.- Returns:
- is this lock a read or write lock?
-