在大量使用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内的执行。

最新文章

  1. resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found.
  2. JavaEE基础(二十一)/IO流
  3. Eclipse导入工程中文乱码问题
  4. centos mysq table is read only
  5. getchar
  6. Java数据库缓存思路
  7. js 正则练习之语法高亮
  8. Ajax应用-定义一套自己的Ajax框架
  9. Hibernate 学习笔记 - 1
  10. TCP/IP参考模型
  11. SDK测试实践
  12. dataTable 实战总结
  13. summary of week
  14. kubernetes云平台管理实战: 滚动升级秒级回滚(六)
  15. ES6之命令妙用
  16. PHP全栈学习笔记18
  17. 转:自旋锁(spinlock)
  18. FFMPEG 中dts和pts区别
  19. 071——VUE中vuex之使用getters计算每一件购物车中商品的总价
  20. SQLSERVER数据库迁移的方法

热门文章

  1. [rook] rook的控制流
  2. java 查看SOAP请求报文
  3. npm install 项目安装遇到问题
  4. 代码注释中的专有词——TODO、FIXME和XXX
  5. spring MVC配置详解(转)
  6. Centos7下安装Oracle11g r2图形化界面数据库
  7. 一对一voip,直播连麦,在线会议,兼容webrtc,IM音视频
  8. C#.NET接收JSON数组
  9. apache2.4 httpd.conf httpd-vhost.conf配置
  10. Cookiecutter: 更好的项目模板工具:(3)高级用法