在大量使用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卡死解决办法的更多相关文章

  1. pycharm(社区版2019.1版本)打开README.md文件卡死解决办法

    现象:pycharm(社区版2019.1版本)打开README.md文件卡死 解决办法: 将插件Markdown support前的勾选√去掉,保存修改后重启pycharm即可

  2. 安装好ubuntu双系统启动时卡死解决办法

    问题描述:在安装完ubuntu双系统后,第一次启动ubuntu系统时,卡死在启动界面(或者黑屏),这大概都是由于显卡驱动的原因,具体不在这里阐述,通过以下方法能成功解决,据我个人经验,这可能是诸多方法 ...

  3. df -h命令卡死解决办法

    1.现象 同事突然反应说有个服务器进入/目录运行 ls  -l 无反应,同时运行df  -h也卡死了.如果你的机器有用到nfs请直接看第四大点. 2.分析 运行mount [conversant@sw ...

  4. Win7下VS2008安装cocos2d-2.0-x-2.0.4模板时, 运行InstallWizardForVS2008.js文件执行失败的解决办法

         今天在Win7环境下的VS2008中安装cocos2d-x模板的过程中,当点击InstallWizardForVS2008.js时,弹出" 没有文件扩展'.js'的脚本引擎&q ...

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

    1.问题描述: 我使用是一个2T移动硬盘,分了5个区 2.分析原因:因为mac OSX的日志式格式需要有EFI分区进行引导,而我的移动硬盘是没有EFI分区的,这样的话就会出现问题: 3.解决办法: 1 ...

  6. SQL Server2005作业执行失败的解决办法

    数据库:SQL Server 2005,运行环境:Windows Server 2008  在数据库里的所有作业都执行失败,包括自动执行和手动执行.在事件查看器里看到的错误报告如下: 该作业失败.  ...

  7. 转:"为自动填充列调整大小期间不能执行此操作"解决办法 .

    转载自:http://blog.csdn.net/zhxingway/article/details/5384690 今天在测试的时候,打开一个窗口突然发现出现以下错误,就算我在打开窗口那个按钮里面和 ...

  8. delphi query阻塞执行 长时间执行sql的解决办法

    delphi query 执行sql一直是阻塞执行,执行长时间的sql语句,程序没响应了,这时候只能用线程技术解决. 如今FDQuery有了CmdExecMode属性,可以设置amCancelDial ...

  9. SQL Server2005/2008 作业执行失败的解决办法

    数据库:SQL Server 2005/2008,运行环境:Windows Server 2008  在数据库里的所有作业都执行失败,包括自动执行和手动执行.在事件查看器里看到的错误报告如下: 该 作 ...

随机推荐

  1. 简单理解PHP-FPM

    php-fpm只是一个php-fastcgi的管理器,为php提供管理服务 1.为什么会出现php-fpm    fpm的出现全部因为php-fastcgi出现,为了很好的管理php-fastcgi而 ...

  2. .NET Core +NuGet 创建打包发布自己的类库包

    1. 创建类库项目 你可以使用现有的 .NET 类库项目用于要打包的代码,或者创建一个简单的项目,.NET CORE 2.1 项目的 类库如下所示: NugetDemo.class using Sys ...

  3. php项目踩到的empty函数的一个坑

    报错信息: PHP Fatal error: Can't use function return value in write context in /目录省略.../XXService.php on ...

  4. AICODER官方小程序和公众号上线了

    小伙伴们,新年好. 在新的一年里,AICODER将继续为大家提供优质的视频资源,为大家提供一个优质的问题解答平台,并且开始提供优质的职业提升类的优质培训资源. 感谢各位一直以来的支持和关注.请加一下A ...

  5. Spring-boot之 swagger2

    Swagger是一个简单但功能强大的API表达工具. 结合springboot 配置起来很简单,附上教程 :https://www.xncoding.com/2017/07/08/spring/sb- ...

  6. python什么时候加self,什么时候不加self

    1.self是什么,一般都说指对象本身,这样说了没了用,说了后还是很难懂,因为这样说了后,仍然完全搞不清楚,什么时候变量前需要加self,什么时候不需要加self. 造成很多人,已经怕了self,不停 ...

  7. sip协议中文讲解

    https://blog.csdn.net/qiuchangyong/article/details/50748854

  8. 133、 Android 自动化测试(转载)

    Android 自动化测试--要点概括http://blog.csdn.net/vshuang/article/details/40595233 A/B测试与灰度发布http://blog.csdn. ...

  9. grafana安装和配置(centos7上配置)

    author:  headsen  chen date:  2019-03-29  10:33:19 1,安装: yum install https://s3-us-west-2.amazonaws. ...

  10. HTTP 错误 500.19 - Internal Server Error 无法读取配置节 system.serviceModel 因为它缺少节声明

    服务器环境:Windows Server2008 R2 Enterprise 配置 IIS 的时候报错. 错误信息: HTTP 错误 500.19 - Internal Server Error无法访 ...