On Aug 4, 2006, at 4:44 PM, Jerry W. Walker wrote:
Hi, Fabrice,
I did lock the child EC in the whole book method :-(
I also tried locking the childEc everywhere it was called
Though I don't think my problem is related to locks, I think its time to give a look to that MultiECLockManager class
Where did I put my Practical WebObjects book ? ;-)
So where can that problem come from ??
The EOEditingContext is referenced in lots of ways that are not particularly visible or intuitive. The basic rule seems to be, if you're interacting with an EO, then that EO's editing context better be locked whether you're directly referencing the editing context or not.
It is NOT SUFFICIENT to lock the editing context only when it is called. It is also not a good idea to lock/unlock the editing context in a component's awake and sleep methods, because it is possible that awake will be called more often than sleep.
MultiECLockManager was created to make locking multiple user created editing contexts easy. Once it's set up, it's nearly as easy as using the Session's defaultEditingContext. Basically, all you do (after setting it up) is a two step process:
EOEditingContext myEC = new EOEditingContext();
((Session)session()).lockManager().registerEditingContext(ec);
That's it! Now you're safe. The MultiECLockManager locks all your registered editing contexts in the Session's awake() method and unlocks them in the Session's sleep() method.
Anything less than this when using editing contexts that you created is generally begging for deadlock problems.
Setting up MultiECLockManager is a bit harder, but is not overly difficult and is well documented in the downloaded package.
I can provide you with notes if you download it and it still doesn't make sense.
If that doesn't do the job, I'm always open to a (full expenses paid) consulting trip to Monaco to give you a hand. :-)
Regards,
Jerry