Product Information > JADE .NET Developer’s Reference > Chapter 2 - Object Management > Enumerating JADE Collections

Enumerating JADE Collections

When a JADE collection is traversed using the default enumerator (for example, indirectly in a standard foreach statement or directly in conjunction with the JoobCollection GetEnumerator method), it remains shared locked until the enumerator is disposed; for example:

foreach (C1 obj1 in collA) //Shared lock is now acquired.
{
    //...examine each member...
}
//Shared lock is now released.

In other cases, when a JADE collection is traversed (for example, via a LINQ query or in conjunction with JoobCollection methods StartingAtIndex, StartingAtKey, or StartingAtObject), the collection is shared locked only for the period when retrieving a snapshot of member references from the associated collection; for example:

IEnumerable<C1> query = from C1 obj1 in collA select obj1;
foreach (C1 obj1 in query)
{
    //...collection is not locked within the loop
}

foreach (C1 obj1 in collA.StartingAtIndex(0))
{
    //...collection is not locked within the loop
}

The automatic locking of collections is particularly important when transactions are involved. If a JADE collection is accessed when in transaction state, it is shared locked and remains so until the transaction ends. This can hold up other JADE sessions wanting to update the collection, and it can also contribute to deadlocks.

Using update locks can help to prevent JADE sessions from being held up when JADE collections are updated, as update locks are compatible with shared locks. For more details, see “Optimizing Locking”, later in this chapter.