CoreData 执行executefetchrequest卡死解决办法
在大量使用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卡死解决办法的更多相关文章
- pycharm(社区版2019.1版本)打开README.md文件卡死解决办法
现象:pycharm(社区版2019.1版本)打开README.md文件卡死 解决办法: 将插件Markdown support前的勾选√去掉,保存修改后重启pycharm即可
- 安装好ubuntu双系统启动时卡死解决办法
问题描述:在安装完ubuntu双系统后,第一次启动ubuntu系统时,卡死在启动界面(或者黑屏),这大概都是由于显卡驱动的原因,具体不在这里阐述,通过以下方法能成功解决,据我个人经验,这可能是诸多方法 ...
- df -h命令卡死解决办法
1.现象 同事突然反应说有个服务器进入/目录运行 ls -l 无反应,同时运行df -h也卡死了.如果你的机器有用到nfs请直接看第四大点. 2.分析 运行mount [conversant@sw ...
- Win7下VS2008安装cocos2d-2.0-x-2.0.4模板时, 运行InstallWizardForVS2008.js文件执行失败的解决办法
今天在Win7环境下的VS2008中安装cocos2d-x模板的过程中,当点击InstallWizardForVS2008.js时,弹出" 没有文件扩展'.js'的脚本引擎&q ...
- mac 上格式化磁盘出现MediaKit报告设备上的空间不足以执行请求的解决办法
1.问题描述: 我使用是一个2T移动硬盘,分了5个区 2.分析原因:因为mac OSX的日志式格式需要有EFI分区进行引导,而我的移动硬盘是没有EFI分区的,这样的话就会出现问题: 3.解决办法: 1 ...
- SQL Server2005作业执行失败的解决办法
数据库:SQL Server 2005,运行环境:Windows Server 2008 在数据库里的所有作业都执行失败,包括自动执行和手动执行.在事件查看器里看到的错误报告如下: 该作业失败. ...
- 转:"为自动填充列调整大小期间不能执行此操作"解决办法 .
转载自:http://blog.csdn.net/zhxingway/article/details/5384690 今天在测试的时候,打开一个窗口突然发现出现以下错误,就算我在打开窗口那个按钮里面和 ...
- delphi query阻塞执行 长时间执行sql的解决办法
delphi query 执行sql一直是阻塞执行,执行长时间的sql语句,程序没响应了,这时候只能用线程技术解决. 如今FDQuery有了CmdExecMode属性,可以设置amCancelDial ...
- SQL Server2005/2008 作业执行失败的解决办法
数据库:SQL Server 2005/2008,运行环境:Windows Server 2008 在数据库里的所有作业都执行失败,包括自动执行和手动执行.在事件查看器里看到的错误报告如下: 该 作 ...
随机推荐
- 微信公众号 chinaxdt 的 解压密码 mima
关于密码:解压密码获取方式第一步关注微信号“chinaxdt”第二步发送信息“mima”即可获取自动回复解压密码 这个 chinaxdt 的微信公众号已经失效,所以大家也不用去加了,密码我这告诉大家. ...
- SQL Server In-Memory OLTP Internals for SQL Server 2016
SQL Server In-Memory OLTP Internals for SQL Server 2016 这份白皮书是在上一份<SQL Server In-Memory OLTP Inte ...
- EntityFramework 动态构造排序 Func<IQueryable<T>, IOrderedQueryable<T>> Dynamic
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; us ...
- [转]Eureka自我保护机制、健康检查的作用、actuator模块监控
Eureka自我保护机制 接着以上篇文章建立的三个工程为基础(eureka-server,uerreg,myweb),默认Eureka是开启自我保护的.我们来做个测试,我们先启动三个工程,我们访问注册 ...
- Android gradle 配置
gradle https://www.cnblogs.com/qianxudetianxia/p/4948499.html flavor https://blog.csdn.net/user11223 ...
- [转]谈NAND Flash的底层结构和解析
这里我想以一个纯玩家的角度来谈谈关于NAND Flash的底层结构和解析,可能会有错误的地方,如果有这方面专家强烈欢迎指正. NAND Flash作为一种比较实用的固态硬盘存储介质,有自己的一些物理特 ...
- 使用Python启动一个简单的服务器
在 Linux 服务器上或安装了 Python 的机器上,Python自带了一个WEB服务器 SimpleHTTPServer,我们可以很简单的使用 python -m SimpleHTTPServ ...
- HttpServletResponse实现文件下载
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import ...
- JS开发中常用的小技巧
1.获取指定范围内的随机数 1 2 3 function getRadomNum(min,max){ return Math.floor(Math.random() * (max - min ...
- 发送消息-配置app_id
$user_id = $curr_workitem["creater_id"]; $user_name = g('dao_user') -> get_by_id($user_ ...