public class DeadlockDetectingLockManager extends DefaultLockManager implements DeadlockChecker, Runnable
DldGlobalTransaction
.
A thread calling lock(Object, Object, long, TimeUnit)
or lockAll(Collection, Object, long, TimeUnit)
would run the deadlock detection algorithm only if all of the following take place:
- the call is made in the scope of a transaction (either locally originated or remotely originated)
- it cannot acquire lock on the given key and the lock owner is another transaction
- when comparing coin toss, this thread would loose against the other one - so it's always the potential loser that runs DLD.
If deadlock is detected then a DeadlockDetectedException
is thrown.
This is subsequently handled in the interceptor chain - locks owned by this tx are released.Modifier and Type | Field and Description |
---|---|
protected boolean |
exposeJmxStats |
configuration, lockContainer, scheduler
Constructor and Description |
---|
DeadlockDetectingLockManager() |
Modifier and Type | Method and Description |
---|---|
boolean |
deadlockDetected(Object pendingOwner,
Object currentOwner)
It checks for deadlock.
|
long |
getDetectedLocalDeadlocks() |
long |
getDetectedRemoteDeadlocks() |
long |
getOverlapWithNotDeadlockAwareLockOwners() |
long |
getTotalNumberOfDetectedDeadlocks() |
void |
init() |
KeyAwareLockPromise |
lock(Object key,
Object lockOwner,
long time,
TimeUnit unit)
Attempts to lock the
key if the lock isn't already held by the lockOwner . |
KeyAwareLockPromise |
lockAll(Collection<?> keys,
Object lockOwner,
long time,
TimeUnit unit)
Same as
LockManager.lock(Object, Object, long, TimeUnit) but for multiple keys. |
void |
resetStatistics() |
void |
run() |
void |
setExposeJmxStats(boolean exposeJmxStats) |
void |
stopScheduler() |
getConcurrencyLevel, getLock, getNumberOfLocksAvailable, getNumberOfLocksHeld, getOwner, inject, isLocked, ownsLock, printLockInfo, unlock, unlockAll, unlockAll
public void init()
public void stopScheduler()
public KeyAwareLockPromise lock(Object key, Object lockOwner, long time, TimeUnit unit)
LockManager
key
if the lock isn't already held by the lockOwner
.
This method is non-blocking and return immediately a LockPromise
. The LockPromise
can (and should)
be used by the invoker to check when the lock is really acquired by invoking LockPromise.lock()
.
lock
in interface LockManager
lock
in class DefaultLockManager
key
- key to lock.lockOwner
- the owner of the lock.time
- the maximum time to wait for the lockunit
- the time unit of the time
argumentKeyAwareLockPromise
associated to this keys.public KeyAwareLockPromise lockAll(Collection<?> keys, Object lockOwner, long time, TimeUnit unit)
LockManager
LockManager.lock(Object, Object, long, TimeUnit)
but for multiple keys.
It ensures no deadlocks if the method is invoked by different lock owners for the same set (or subset) of keys.
lockAll
in interface LockManager
lockAll
in class DefaultLockManager
keys
- keys to lock.lockOwner
- the owner of the lock.time
- the maximum time to wait for the lockunit
- the time unit of the time
argumentKeyAwareLockPromise
associated to this keys.public boolean deadlockDetected(Object pendingOwner, Object currentOwner)
DeadlockChecker
It accepts two arguments: the pendingOwner
is a lock owner that tries to acquire the lock and the currentOwner
is the current lock owner. If a deadlock is detected and the pendingOwner
must rollback, it
must return true
. If no deadlock is found or the currentOwner
must rollback, it must return false
.
This method may be invoked multiples times and in multiple threads. Thread safe is advised.
deadlockDetected
in interface DeadlockChecker
pendingOwner
- a lock owner that tries to acquire the lock.currentOwner
- the current lock owner.true
if a deadlock is detected and the pendingOwner
must rollback.public void setExposeJmxStats(boolean exposeJmxStats)
public long getTotalNumberOfDetectedDeadlocks()
public void resetStatistics()
public long getDetectedRemoteDeadlocks()
public long getDetectedLocalDeadlocks()
public long getOverlapWithNotDeadlockAwareLockOwners()
Copyright © 2023 JBoss, a division of Red Hat. All rights reserved.