CoreData 执行executefetchrequest卡死解决办法
来源:互联网 发布:形式与政策网络课答案 编辑:程序博客网 时间:2024/05/21 14:08
在大量使用GCD和block以后发现程序会卡死在executefetchrequest执行。
反复测试无果。添加锁也无效。想来想去没发现问题。
容忍了就当人品问题。2天以后实在忍无可忍。
替换performBlock执行块得到如下错误
nsmanagedobjectcontext that was created with a queue
翻英文资料查看。
http://stackoverflow.com/questions/4800889/what-does-apple-mean-when-they-say-that-a-nsmanagedobjectcontext-is-owned-by-the
苹果官方文档资料
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdConcurrency.html#//apple_ref/doc/uid/TP40003385-SW1
看到如下一句话
Fetch in the Background for UI Responsiveness
The executeFetchRequest:error:
method intrinsically scales its behavior appropriately for the hardware and work load. If necessary, the Core Data will create additional private threads to optimize fetching performance. You will not improve absolute fetching speed by creating background threads for the purpose. It may still be appropriate, however, to fetch in a background thread or queue to prevent your application’s user interface from blocking. This means that if a fetch is complicated or returns a large amount of data, you can return control to the user and display results as they arrive.
Following the thread confinement pattern, you use two managed object contexts associated with a single persistent store coordinator. You fetch in one managed object context on a background thread, and pass the object IDs of the fetched objects to another thread. In the second thread (typically the application's main thread, so that you can then display the results), you use the second context to fault in objects with those object IDs (you use objectWithID:
to instantiate the object). (This technique is only useful if you are using an SQLite store, since data from binary and XML stores is read into memory immediately on open.)
明白了原来在线程中NSManagedObjectContext会创建一些私有方法。跨线程使用时候就会出问题。
解决办法就是多个线程执行时候创建多个NSManagedObjectContext管理。关联到NSPersistentStoreCoordinator
同理解决
GCD
NSOperation内的执行。
- CoreData 执行executefetchrequest卡死解决办法
- Coredata之 executeFetchRequest 和 performFetch
- VC6link卡死解决办法
- myeclipse启动卡死解决办法
- apache经常卡死解决办法
- av_read_frame 阻塞卡死解决办法
- quartz执行卡死--强制中断线程
- Ubuntu下图形界面卡死的解决办法
- python卡死x-window解决办法
- VC6编译卡死之解决办法
- VC6编译卡死之解决办法
- Ubuntu下图形界面卡死的解决办法
- VC6 编译卡死之解决办法
- 远程截图卡死的解决办法
- 织梦后台卡死的解决办法
- eclipse编译校验JS卡死解决办法
- 织梦CMS后台卡死的解决办法
- VS2010拖动用户控件卡死解决办法
- NPAPI开发详解,Windows版
- .Net 生成API文档(一)
- 二叉树转链表
- Extjs4表单布局经验
- Java多线程(三)之ConcurrentHashMap深入分析
- CoreData 执行executefetchrequest卡死解决办法
- Java多线程(四)之ConcurrentSkipListMap深入分析
- Java多线程(五)之BlockingQueue深入分析
- C++ 虚函数表解析
- 市场营销学4——市场调研与预测
- ExamSoftware介绍
- Java多线程(六)之Deque与LinkedBlockingDeque深入分析
- Button 中实现点击前后字体颜色的变化
- Matlab Class实现Queue