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

转载于:https://www.cnblogs.com/jxst441192/p/3571092.html

CoreData 执行executefetchrequest卡死解决办法相关推荐

  1. linux 卡在grub_详解ubuntu双系统启动时卡死解决办法

    ubuntu双系统启动时卡死解决办法(在ubuntu16.04和18.04测试无误) 问题描述: 在安装完ubuntu双系统后,第一次启动ubuntu系统时,卡死在启动界面(或者黑屏),这大概都是由于 ...

  2. mac双系统装mysql启动不了了_详解ubuntu双系统启动时卡死解决办法

    详解ubuntu双系统启动时卡死解决办法 ubuntu双系统启动时卡死解决办法(在ubuntu16.04和18.04测试无误) 问题描述: 在安装完ubuntu双系统后,第一次启动ubuntu系统时, ...

  3. c# http请求执行超时,解决办法(给某个方法设定超时时间)

    c# http请求执行超时,解决办法(给某个方法设定超时时间) 参考文章: (1)c# http请求执行超时,解决办法(给某个方法设定超时时间) (2)https://www.cnblogs.com/ ...

  4. php 脚本会超时吗,PHP脚本执行超时的解决办法

    PHP脚本执行超时的解决办法在php中默认脚本执行超时时间为30秒了,如果你未进行设置30秒之后如果你的脚本还未执行完就会超时了,下面我来给大详解解决PHP脚本执行超时的方法. php.ini 中缺省 ...

  5. mac 上格式化移动硬盘出现MediaKit报告设备上的空间不足以执行请求的解决办法

    突发奇想的想用自己的移动硬盘给Mac电脑做备份,但是硬盘格式不对,就手贱点了抹掉.后来提示mac 上格式化移动硬盘出现MediaKit报告设备上的空间不足以执行请求的解决办法.网上找了好久没有找到解决 ...

  6. 楚留香获取服务器信息卡住了,楚留香手游角色卡住不动怎么办 卡死解决办法...

    楚留香手游角色卡住不动怎么办?来看看卡死解决办法.由于手机,网络和服务器等等原因,玩家会出现角色卡住动不了,操作界面消失,无法切换场景等等情况,非常影响游戏体验,来看看怎么解决吧. 楚留香手游角色卡住 ...

  7. gazebo卡了_ardupilot gazebo打开卡死解决办法

    首先这是官网安装gazebo以及搭建模拟环境的教程,里面缺少了配置环境变量的步骤 这里我做一个补充 首先要打开 ~/.bashrc 文件 添加以下内容 source /usr/share/gazebo ...

  8. 坦克游戏服务器未响应,《坦克世界》退出战斗 退出战斗卡死解决办法

    不知道大家有没有过,在玩坦克世界时,退出战斗会有卡死的情况.小编是没有遇到过.但却看到很多游戏中的朋友反映过.下面小编为大家整理了几个关于退出战斗卡死的情况,以及遇到此情况的玩家的解决办法.希望能给大 ...

  9. VC6link卡死解决办法

    VC6在编译的时候,linking.....,一直就这样link下去,只能在任务管理器中强行退出VC6再重新打开,不过重新打开后问题依旧,实在让人恼火. 网上传说这是VC6的bug,解决vc6卡死的办 ...

  10. jupyter执行显示error解决办法

    在使用jupyter的时候发现运行没有成功,且显示error的,并且终端提示并且自动退出了!! Bad file descriptor (C:\user\lihaian\work\src\epoll. ...

最新文章

  1. Kali Linux缺少ifconfig命令
  2. set OpenCV_ROOT
  3. visual studio 2008 快捷键
  4. mysql charindex_mysql中替代charindex的函数substring_index、find_in_set | 学步园
  5. java 小数运算 少0.1_计算器是如何实现0.1的?
  6. python实现批量更改xml文件中内容替换
  7. d3 v5 api select
  8. 最短路径(二维矩阵)
  9. 移植JDK,确实需要CPU指令级的工作
  10. 瀑布模型、V模型、原型模型、增量模型、螺旋模型、喷泉模型
  11. mathtype过期,不用每次都去回顾教程
  12. PADS Logic原理图设计
  13. python-docx处理word文档功能详细说明
  14. 板线分离嵌入式RFID读卡模块NFC读写模块HX880系列的应用案例
  15. moment的常见用法总结
  16. python简单实现微信抢红包功能
  17. 我改变世界、我已看透、我不再是个程序员-IT创世诸神如是说
  18. 用双向宽搜来提高搜索效率
  19. 计算机pe启动蓝屏怎么办,U盘重装系统进入PE蓝屏怎么办
  20. sql盲注二分法注入脚本

热门文章

  1. python数据类型汇总_python知识汇总(数据类型和字符串)
  2. 基于SSM的实验室预约系统
  3. 基于SSM的疫情数据统计分析系统
  4. linux apache支持ipv6,如何在Nginx和Apache中启用IPv6?
  5. 解决Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile
  6. php5.3 PHP5.4 PHP5.5 php5.6 新特性/使用PHP5.5/PHP5.6要注意的
  7. MyBatis 持久化框架快速使用入门(Xml配置版)
  8. ES6 Map 数据结构、ES6 箭头函数
  9. @Configuration、@Bean 装配组件 与 @Resource 与 @Autowired 与 @Qualifier 、@Primary 获取组件
  10. 阶段3 2.Spring_08.面向切面编程 AOP_4 spring基于XML的AOP-配置步骤