The Lock method of the JoobContext class is used to explicitly lock objects.
void Lock(JoobObject receiver, LockType type, LockDuration duration, TimeSpan waitTime);
LockType and LockDuration are enums with the following sets of values.
LockType.Shared
LockType.Reserve
LockType.Update
LockType.Exclusive
LockDuration.Transaction
LockDuration.Session
Objects are explicitly unlocked using the JoobContext Unlock method.
void Unlock(JoobObject receiver);
The Unlock method call is ignored if the JADE session is in transaction state (that is, it has a JADE transaction in effect) or in load state (that is, it is executing within a BeginLoad/EndLoad bracket, described under “Load State”). Instead, provided that the lock is of transaction duration, the object will be unlocked when the transaction is committed or rolled back, or when load state is terminated.
Session duration locks must be unlocked using the Unlock method outside transaction state.
All locks held by a JADE session are released, regardless of duration, when the session becomes inactive, which typically is when its JoobContext instance is disposed of.
The following code fragment locks two JADE objects, then unlocks them:
//Request a shared lock, transaction duration, 1 second time out. context.Lock(obj1, LockType.Shared, LockDuration.Transaction, TimeSpan.FromSeconds(1)); //Request a reserve lock, session duration, 5 second time out. context.Lock(obj2, LockType.Reserve, LockDuration.Session, TimeSpan.FromSeconds(5)); context.Unlock(obj1); context.Unlock(obj2);