Issuing regarding using different threads for parsing the JSONs ,saving CBLModels and performing UI operation at the same time

70 views
Skip to first unread message

rupa selvaraj

unread,
Aug 7, 2014, 6:48:23 AM8/7/14
to mobile-c...@googlegroups.com
Hi,

Currently, based on the number of files, we will detach separate thread with separate database pointer (using cblmanager copy) for file parsing.That is working fine.But the app is crashing when we try to use the same model, for UI loading  and for parsing and saving models at the same time but using different threads and pointers only.

Exception we got,
 <Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Document already has a model'

What could be the issue, we are using the different pointers only and accessing the model using that pointer only?
Parsing also takes sometime.For 5 jsons files,each of size 700kb to 1Mb takes 5 to 10 seconds.


Our requirement is to perform UI operation at the same time of parsing.Please help us to resolve this issue. Thanks in advance.

Jens Alfke

unread,
Aug 7, 2014, 8:06:28 PM8/7/14
to mobile-c...@googlegroups.com

On Aug 7, 2014, at 3:48 AM, rupa selvaraj <rups...@gmail.com> wrote:

Currently, based on the number of files, we will detach separate thread with separate database pointer (using cblmanager copy) for file parsing.That is working fine.But the app is crashing when we try to use the same model, for UI loading  and for parsing and saving models at the same time but using different threads and pointers only.

You can't use a CBLModel on a different thread than the one it was created on. (Just like all the other CBL objects.)

Parsing also takes sometime.For 5 jsons files,each of size 700kb to 1Mb takes 5 to 10 seconds.

That's about what I'd expect. I've spent some time looking at JSON parsing performance; a lot of it isn't in the actual parsing but in allocating all of the objects. If you're only going to be using part of the data in the documents, you can speed up the parsing by using a streaming library that doesn't create objects for everything. I like jsonsl.

—Jens

rupa selvaraj

unread,
Aug 12, 2014, 1:44:22 AM8/12/14
to mobile-c...@googlegroups.com
No no actually we are accessing the models on the thread it was created only.. But the scenario is , consider i have xyz model , in one thread i am trying to fetch xyz model from database for UI display and in other thread parsing is happening and trying to save xyz model at the same time(both using different database pointers and threads only).


Exception we got,
 <Error>: *** Terminating app due to uncaught exception '
NSInternalInconsistencyException', reason: 'Document already has a model


Jens Alfke

unread,
Aug 12, 2014, 2:51:33 AM8/12/14
to mobile-c...@googlegroups.com

On Aug 11, 2014, at 10:44 PM, rupa selvaraj <rups...@gmail.com> wrote:

Exception we got,
 <Error>: *** Terminating app due to uncaught exception '
NSInternalInconsistencyException', reason: 'Document already has a model

What's the full backtrace?

—Jens
Reply all
Reply to author
Forward
0 new messages