public class HierarchicalLock.SharedLock extends Object implements HierarchicalLock.AcquiredLock
HierarchicalLock
. This object is used to
release the lock or to change it (via promotion or demotion).
Unlike other types of promotion and demotion, promoting a shared lock to its parent or demoting to one of its children will succeed, even if more than one such shared lock is held (from re-entrance).
Modifier and Type | Method and Description |
---|---|
HierarchicalLock.SharedLock |
demoteToChild(HierarchicalLock child)
Demotes this lock to a shared lock on one of its children.
|
HierarchicalLock.SharedLock |
demoteToChildInterruptibly(HierarchicalLock child)
Demotes this lock to a shared lock on one of its children, waiting interruptibly until it
is available.
|
HierarchicalLock.ExclusiveLock |
promoteToExclusive()
Promotes this shared lock into an exclusive lock.
|
HierarchicalLock.ExclusiveLock |
promoteToExclusiveInterruptibly()
Promotes this shared lock into an exclusive lock, waiting interruptibly until the exclusive
lock becomes available.
|
HierarchicalLock.SharedLock |
promoteToParent()
Promotes this lock to a shared lock on its parent.
|
HierarchicalLock.SharedLock |
tryDemoteToChild(HierarchicalLock child)
Tries to demote this lock to a shared lock on one of its children, returning immediately if
the child lock is unavailable.
|
HierarchicalLock.SharedLock |
tryDemoteToChild(HierarchicalLock child,
long timeLimit,
TimeUnit unit)
Tries to demote this lock to a shared lock on one of its children, waiting for the
specified amount of time before giving up.
|
HierarchicalLock.ExclusiveLock |
tryPromoteToExclusive()
Promotes this shared lock into an exclusive lock, returning immediately if the exclusive
lock is unavailable.
|
HierarchicalLock.ExclusiveLock |
tryPromoteToExclusive(long timeLimit,
TimeUnit unit)
Promotes this shared lock into an exclusive lock, waiting up to the given amount of time
before giving up.
|
void |
unlock()
Releases the held lock.
|
public void unlock()
HierarchicalLock.AcquiredLock
unlock
in interface HierarchicalLock.AcquiredLock
public HierarchicalLock.ExclusiveLock promoteToExclusive()
HierarchicalLock
. This method will
block until the exclusive lock becomes available.IllegalStateException
- if this thread does not hold this lock or has already
released it; or if the shared lock has been acquired by this thread more than once (in a
re-entrant manner)DeadlockException
- if waiting for the exclusive lock would result in a deadlock
(e.g. this thread holds a lock for which another thread is waiting, and that thread, or
some other thread that directly or indirectly is waiting on it, is holding the exclusive
lock)public HierarchicalLock.ExclusiveLock promoteToExclusiveInterruptibly() throws InterruptedException
HierarchicalLock
.InterruptedException
- if this thread is interrupted while waiting for the exclusive
lock to become availableIllegalStateException
- if this thread does not hold this lock or has already
released it; or if the shared lock has been acquired by this thread more than once (in a
re-entrant manner)DeadlockException
- if waiting for the exclusive lock would result in a deadlock
(e.g. this thread holds a lock for which another thread is waiting, and that thread, or
some other thread that directly or indirectly is waiting on it, is holding the exclusive
lock)public HierarchicalLock.ExclusiveLock tryPromoteToExclusive()
HierarchicalLock
.null
if it is not availableIllegalStateException
- if this thread does not hold this lock or has already
released it; or if the shared lock has been acquired by this thread more than once (in a
re-entrant manner)DeadlockException
- if waiting for the exclusive lock would result in a deadlock
(e.g. this thread holds a lock for which another thread is waiting, and that thread, or
some other thread that directly or indirectly is waiting on it, is holding the exclusive
lock)public HierarchicalLock.ExclusiveLock tryPromoteToExclusive(long timeLimit, TimeUnit unit) throws InterruptedException
HierarchicalLock
.timeLimit
- the limit of time to wait for the lockunit
- the unit of the time limitnull
if the time limit lapsed before
the lock became availableInterruptedException
- if this thread is interrupted while waiting for the exclusive
lock to become availableIllegalStateException
- if this thread does not hold this lock or has already
released it; or if the shared lock has been acquired by this thread more than once (in a
re-entrant manner)DeadlockException
- if waiting for the exclusive lock would result in a deadlock
(e.g. this thread holds a lock for which another thread is waiting, and that thread, or
some other thread that directly or indirectly is waiting on it, is holding the exclusive
lock)public HierarchicalLock.SharedLock demoteToChild(HierarchicalLock child)
HierarchicalLock.SharedLock
that represents the lock on the
child. This method will block until the child lock is available.demoteToChild
in interface HierarchicalLock.AcquiredLock
child
- the child of this lock to which this lock is demotedIllegalStateException
- if this thread does not hold this lock or has already
released it; or if the given lock is not actually a child of the
HierarchicalLock
which produced this HierarchicalLock.SharedLock
DeadlockException
- if waiting for the child lock would result in a deadlock (e.g.
this thread holds a lock for which another thread is waiting, and that thread, or some
other thread that directly or indirectly is waiting on it, is holding the child lock)public HierarchicalLock.SharedLock demoteToChildInterruptibly(HierarchicalLock child) throws InterruptedException
HierarchicalLock.SharedLock
that represents the lock on the child.child
- the child of this lock to which this lock is demotedDeadlockException
InterruptedException
- if this thread is interrupted while waiting for the child lock
to become availableIllegalStateException
- if this thread does not hold this lock or has already
released it; or if the given lock is not actually a child of the
HierarchicalLock
which produced this HierarchicalLock.SharedLock
DeadlockException
- if waiting for the child lock would result in a deadlock (e.g.
this thread holds a lock for which another thread is waiting, and that thread, or some
other thread that directly or indirectly is waiting on it, is holding the child lock)public HierarchicalLock.SharedLock tryDemoteToChild(HierarchicalLock child)
HierarchicalLock.SharedLock
that represents the lock on the child.child
- the child of this lock to which this lock is demotednull
if it was not availableDeadlockException
IllegalStateException
- if this thread does not hold this lock or has already
released it; or if the given lock is not actually a child of the
HierarchicalLock
which produced this HierarchicalLock.SharedLock
DeadlockException
- if waiting for the child lock would result in a deadlock (e.g.
this thread holds a lock for which another thread is waiting, and that thread, or some
other thread that directly or indirectly is waiting on it, is holding the child lock)public HierarchicalLock.SharedLock tryDemoteToChild(HierarchicalLock child, long timeLimit, TimeUnit unit) throws InterruptedException
HierarchicalLock.SharedLock
that represents the lock on the child.child
- the child of this lock to which this lock is demotedtimeLimit
- the limit of time to wait for the lockunit
- the unit of the time limitnull
if the time limit lapsed
before the lock became availableInterruptedException
- if this thread is interrupted while waiting for the child lock
to become availableIllegalStateException
- if this thread does not hold this lock or has already
released it; or if the given lock is not actually a child of the
HierarchicalLock
which produced this HierarchicalLock.SharedLock
DeadlockException
- if waiting for the child lock would result in a deadlock (e.g.
this thread holds a lock for which another thread is waiting, and that thread, or some
other thread that directly or indirectly is waiting on it, is holding the child lock)public HierarchicalLock.SharedLock promoteToParent()
HierarchicalLock.SharedLock
that represents the lock on the parent. This
method does not need to block since all acquired locks also hold implicit shared locks on
parent/ancestor locks.promoteToParent
in interface HierarchicalLock.AcquiredLock
IllegalStateException
- if this thread does not hold this lock or has already
released it; or if the lock that produced this HierarchicalLock.SharedLock
is a root lock and
does not have a parentDeadlockException
- if waiting for the parent lock would result in a deadlock (e.g.
this thread holds a lock for which another thread is waiting, and that thread, or some
other thread that directly or indirectly is waiting on it, is holding the parent lock)