A deadlock can occur with only one object being involved. For example, this can happen in conjunction with lock type upgrades, as follows.
The initial situation is:
Session A and Session B both have a shared lock on Object 1
The attempted actions are:
Session A attempts to upgrade the lock type to exclusive
Session B also attempts to upgrade the lock type to exclusive
The outcome is:
Neither session can proceed, because they are waiting for each other due to them both having a shared lock
This type of deadlock occurs with the following sort of code sequence.
TimeSpan timeOut = TimeSpan.FromSeconds(5); using ( System.Data.IDbTransaction tran = context.BeginTransaction()) { context.Lock(obj1, LockType.Shared, LockDuration.Transaction, timeOut); //... context.Lock(obj1, LockType.Exclusive, LockDuration.Transaction, timeOut); //... tran.Commit(); }
Two JADE sessions simultaneously executing this sequence using the same JADE object can get in a deadlock situation.
This type of sequence can occur subtly. For example, consider the following pattern where a JADE session checks to see if a JADE collection contains an object, then adds it to the collection if it is not there.
using (System.Data.IDbTransaction tran = context.BeginTransaction()) { if (!allPeople.Contains(person)) allPeople.Add(person); tran.Commit(); }
A deadlock can result if two JADE sessions execute this sequence at the same time with the same collection. Using Contains places a shared lock on the collection, and adding the member attempts to upgrade the lock to exclusive (or update). Both JADE sessions can end up with a shared lock on the collection, thereby preventing one another from upgrading.