Re: Core Data & threads [re: Ping: Look for hints for "nested transaction" problem with Core Data]
Re: Core Data & threads [re: Ping: Look for hints for "nested transaction" problem with Core Data]
- Subject: Re: Core Data & threads [re: Ping: Look for hints for "nested transaction" problem with Core Data]
- From: Pierre Chatelier <email@hidden>
- Date: Sat, 17 Mar 2007 12:13:13 +0100
If you suspect the objects have already been fetched by someone
else (or yourself previously), use -objectWithID: or -
objectRegisteredForID: instead of -executeFetchRequest:
That's right, but here is the test case I am thinking about :
I have two threads A and B, each one owning their own managed object
context Ma and Mb
thread A computes objects o1, o2, o3, ..., [save], o7, o8
thread B computes objects o11, o7
Since o7 has not been saved in thread A, it has a temporary objectID.
So, I cannot fetch it in Mb, neither with executeFetchRequest, nor
objectWithID.
Is there a solution in this case ?
The save-then-notify-others idiom works quite well with multiple
threads in Core Data.
I think it would be too expensive to call save: for each object,
because it is many of small objects.
So, yes, I could recompute o7 in thread B, but it is not optimal. If
save occurs every two minutes, this may be 2 minutes of computation
lost.
Regards,
Pierre Chatelier
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden