|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Lockable
An instance of Lockable
is a resource on which
read- or write-locked tasks can be performed.
Several read-locked tasks may be executed concurrently, while
only a single write-locked task may be executed at the same
time. A write-locked task excludes the concurrent
execution of both read- and write-locked tasks, so a write lock
is an exclusive lock.
Locks are re-entrant: A task which is executed using a lock may execute further nested, locked tasks in the same thread.
Tasks which should be executed using a lock are specified by
implementations of LockProtectedRunnable
.
The lock/unlock operations are performed implicitly before
and after invocation of the method run
in
LockProtectedRunnable
. However,
a task may invoke Lock.retain()
on its
lock in order to suppress the unlock operation after the task
has completed: In this case, the lock may be kept for a while and
even passed to another thread until it is eventually passed
to one of the execute
methods of Lockable
.
Nested Class Summary | |
---|---|
static class |
Lockable.DeadLockException
An instance of DeadLockException is thrown
by executeForcedly(LockProtectedRunnable, boolean)
if the operation would result in a dead-lock condition. |
Method Summary | |
---|---|
void |
execute(LockProtectedRunnable task,
boolean write)
Asynchronously executes a task such that it possesses
a lock on this Lockable . |
void |
execute(LockProtectedRunnable task,
Lock retained)
Asynchronously executes a task using a lock which
has been retained before within another task. |
void |
executeForcedly(LockProtectedRunnable task,
boolean write)
Synchronously executes a task such that it possesses
a lock on this Lockable . |
void |
executeForcedly(LockProtectedRunnable task,
Lock retained)
Synchronously executes a task using a lock which
has been retained before within another task. |
long |
getMaxWaitingTime()
Returns the waiting time of the pending task which is waiting longest, or -1 if there is no pending task. |
int |
getQueueLength()
Returns the current number of tasks which are waiting for locked execution. |
boolean |
isLocked(boolean write)
Determines if the current thread has a lock for this Lockable . |
Method Detail |
---|
void execute(LockProtectedRunnable task, boolean write)
task
such that it possesses
a lock on this Lockable
. Note that the execution
is asynchronous, so that the thread in which
the task will actually be executed may differ from the current thread.
task
- the task to executewrite
- shall a write lock be obtained?void execute(LockProtectedRunnable task, Lock retained)
task
using a lock which
has been retained before within another task.
Note that the execution
is asynchronous, so that the thread in which
the task will actually be executed may differ from the current thread.
task
- the task to executeretained
- the previously retained lockLock.retain()
void executeForcedly(LockProtectedRunnable task, boolean write) throws java.lang.InterruptedException, Lockable.DeadLockException
task
such that it possesses
a lock on this Lockable
. The execution
is performed in the current thread.
task
- the task to executewrite
- shall a write lock be obtained?
java.lang.InterruptedException
Lockable.DeadLockException
void executeForcedly(LockProtectedRunnable task, Lock retained) throws java.lang.InterruptedException
task
using a lock which
has been retained before within another task. The execution
is performed in the current thread.
task
- the task to executeretained
- the previously retained lock
java.lang.InterruptedException
Lock.retain()
long getMaxWaitingTime()
-1
if there is no pending task.
int getQueueLength()
boolean isLocked(boolean write)
Lockable
.
write
- check for write locks only (true
)
or for both read and write locks (false
)
true
if the current thread has a lock
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |