*/
public void waitForLock(ObjectLock lock, Transaction tx)
throws LockingException
{
Transaction writerTx;
ObjectLock writerWaitsForLock;
// test for deadlock
writerTx = lock.getWriter();
while (writerTx != null)
{
writerWaitsForLock = (ObjectLock) _waitsFor.get(writerTx);
if (writerWaitsForLock == null)
{
break;
}
writerTx = writerWaitsForLock.getWriter();
if (writerTx == null)
{
break;
}
if (writerTx == tx)
{
StringBuffer sb = new StringBuffer();
// deadlock detected.
// Now we traverse the cycle once more to provide more info
writerTx = lock.getWriter();
sb.append(lock.getTargetIdentity());
while (writerTx != tx)
{
writerWaitsForLock = (ObjectLock) _waitsFor.get(writerTx);
sb.append(" -> ");
sb.append(writerWaitsForLock.getTargetIdentity());
writerTx = writerWaitsForLock.getWriter();
}
throw new DeadlockException(sb.toString());
}
}