Re: Synchronized Editing Context for Locking/Unlocking
Re: Synchronized Editing Context for Locking/Unlocking
- Subject: Re: Synchronized Editing Context for Locking/Unlocking
- From: Ken Anderson <email@hidden>
- Date: Fri, 3 Sep 2010 11:14:27 -0400
One other important point....
You should take great care to not end up with locks that cross each other. I've run into huge problems when I try to synchronize sections of code that go in and out of EOF. It's real easy to end up with:
thread 1:
synchronize (obj1) - success
ec.lock() - waiting
thread 2:
ec.lock() - success
synchronize (obj1) - waiting
It's easy to avoid the obtuse cases of this, but when the code that locked the object makes a call to something else then a call to something else, it's very difficult to track down.
I ended up removing most synchronizes() from my apps and use implicit locking inside the EC to 'OK' access to other serializable things.
Ken
On Sep 3, 2010, at 7:59 AM, Farrukh Ijaz wrote:
> Hi,
>
> What is the difference between the two? I noticed both work almost the same way.
>
> Usage 1:
>
> try {
> editingContext().lock();
> // Do your stuff
> } finally {
> editingContext().unlock();
> }
>
> Usage 2:
>
> synchronized(editingContext()) {
> // Do your stuff
> }
>
> Thanks,
>
> Farrukh _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden