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 在数据库里的所有作业都执行失败,包括自动执行和手动执行.在事件查看器里看到的错误报告如下: 该 作 ...
随机推荐
- AspectF写法
AspectF.Define .ProgressBar(caption) .Do(() => { if (!SpecialMenuClick(midForm, tag)) { DockBarSh ...
- InputStream为什么不能被重复读取?
最近上传阿里云的时候同一个文件上传两个服务地址,第一个文件读取以后第二个再去读取就拿不到了.代码如下: //内网上传OSS获取key值 String ossKey = OSSClientUtil.ge ...
- sshpass 实现shell脚本直接加载密登录服务器
主要命令:sshpass 这个命不是系统自带的,需要安装: # which sshpass/usr/bin/sshpass[root@666 tools]# rpm -qf /usr/bin/sshp ...
- java.util.function 中的 Function、Predicate、Consumer
函数式接口: 函数式接口(Functional Interface)就是一个有且仅有一个抽象方法,但可以有多个非抽象方法的接口. 函数式接口可以被隐式转换为 Lambda 表达式. Function ...
- Android Studio编译报错“java.lang.OutOfMemoryError: GC overhead limit exceeded
1.在build.gradle添加脚本指定编译堆内存 如果在整个工程中生效,则在build.gradle中增加如下配置: android { .............. dexOptions { i ...
- Java中Access restriction:····的解决方法
http://blog.csdn.net/bit2012_2015/article/details/22798779 ————————————————————————————————————————— ...
- Linux操作环境下配置MMIX环境
一.概述 MMIX用途:高德纳写的<计算机程序设计艺术>,使用 MMIXAL 来编写代码,解释算法. 环境:Ubuntu 桌面版18.04. 二.操作步骤 1,创建MMIX文件夹并切入该文 ...
- openwrt官方固件怎么中继网络
关键一点,取消勾
- tensorflow c/c++库使用方法
tensorflow目前支持最好的语言还是python,但大部分服务都用C++ or Java开发,一般采用动态链接库(.so)方式调用算法,因此tensorflow的c/c++ API还是有必要熟悉 ...
- iowait
https://www.cnblogs.com/fuyuanming/articles/6497005.html