Page 1 of 1

discreteLock

Posted: Sat Nov 03, 2012 3:02 am
by ghosttie
When would you not want to use discreteLock on foreach?

Re: discreteLock

Posted: Sat Nov 03, 2012 2:48 pm
by murray
When would you not want to use discreteLock on foreach?
... in cases where you want to ensure that the collection you are iterating is not changed by other processes.
You may be wanting to add up a total or count a number of objects, without concurrent processes adding or deleting objects during the iteration. It depends on your requirements.
I remember someone asking the related question "why does foreach always lock the collection for the entire iteration?" in a Jade training course many years back (version 5). The answer from the Jade trainer was to the effect of: "why wouldn't you want it that way?" and advocated the requirement for an invariant collection.
Obviously there are various cases, so use what's best in each case.

Re: discreteLock

Posted: Mon Nov 05, 2012 9:16 am
by JohnP
If you are quickly iterating a large number of entries through the collection and there is no contention with updaters, it can be quicker without the discreteLock, since the collection lock is obtained only once. Normally the difference would be small, but if everything is in the node cache, the amount of time doing locks could become noticeable.

Re: discreteLock

Posted: Mon Nov 05, 2012 1:43 pm
by suzuki1100
Where the collection poses no issues with updates or locking contention.
i.e. its a transient collection available only to the current process