多线程数据库获取xcode [英] multithread database fetch xcode

查看:35
本文介绍了多线程数据库获取xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,提前感谢您的帮助,

Hi thank you for the help in advance,

我看了一些帖子,对多线程有点困惑.看起来它可能很容易,但是我对编程很陌生,所以我仍在努力掌握这一点.

I have looked at some of the posts and I am a bit confused about the multi threading. It seems that it may be pretty easy, however I am very new to programming so I am still trying to grasp this.

这是从数据库中提取数据的两个调用,它们永远保持原样......所以我正在考虑对这些进行多线程处理,直到我可以学习如何为此构建核心数据.现在我正在使用 sqllite 并且数据库涉及 10,000 多个食谱......所以不像我想要的那样快......

These are two calls to pull data from a database, and they take forever as it is... So I'm thinking about multithreading these until I can learn how to build a core data for this. Right now i am using sqllite and the database involves 10,000 + recipes... So not lightning fast like I would like...

请告诉我您的想法,以及我如何才能让这些事情同时发生?(如果可能的话)

Please let me know what you think, and how I can make these happen maybe simultaneously? (If thats even possible)

提前致谢.

requestCount++;
[[DataPuller sharedDataPuller] getAllDeletedRecipeList];
[DataPuller sharedDataPuller].target = self;


requestCount++;
[[DataPuller sharedDataPuller] getAllRecipesList];
[DataPuller sharedDataPuller].target = self;

推荐答案

如果你在做 SQLite,你可能想考虑使用 FMDB,它 (a) 让你摆脱 sqlite3 调用的杂草;(b) 提供了一个 FMDatabaseQueue,它允许您协调来自多个队列的查询,这样数据操作就不会相互交叉.

If you're doing SQLite, you might want to contemplate using FMDB which (a) gets you out of the weeds of sqlite3 calls; and (b) offers a FMDatabaseQueue which allows you to coordinate queries from multiple queues, so that the data operations don't stumble across each other.

话虽如此,您建议您遇到了重大的性能问题,您希望通过转向 Core Data 或使用 SQLite 进行多线程来解决这些问题.那不太可能.本地数据库操作的性能不佳通常更多地与您的应用程序设计有关(例如,尝试检索所有 10,000 个配方的全部详细信息不太明智……您可能只想检索唯一标识符,也许只是那些给定屏幕所需,然后仅在稍后根据需要检索给定配方的详细信息).对于本地数据库交互,您很少需要考虑多线程实现,而只需将系统设计为在演示所需的任何给定点检索尽可能少的信息.我个人发现我的数据库驱动应用程序通常只需要在我与某些远程 Web 服务进行广泛交互时才需要多线程(在这种情况下,它是服务器数据的检索和在单独线程上进行的解析,不一定是数据库操作本身).

Having said that, you suggest that you're having significant performance issues which you're hoping to solve with a shift to Core Data or going multi-threaded with SQLite. That's unlikely. Poor performance of local database operations is generally more of a matter of your application design (e.g. it's unlikely to be wise to try to retrieve the entire details for all 10,000 recipes ... you probably want to retrieve just the unique identifiers, perhaps only those required for the given screen, and then only retrieve the particulars for a given recipe at a later point as you need that). For local database interaction, you rarely have to contemplate a multithreaded implementation, but rather just design the system to retrieve the least possible information at any given point that you need for the presentation. I personally find that my database-driven apps generally only need to go multithreaded when I'm doing extensive interaction with some remote web service (in which case, it's the retrieval of server data and the parsing of that which goes on the separate thread, not necessarily the database operations themselves).

如果您的菜谱应用存在性能问题,我建议您提交一个更详细的问题,其中包含代码示例,以阐明您的特定性能问题.如果多线程不是解决方案的一部分,我也不会感到惊讶.很可能,在任何给定点适当使用索引和更明智地检索信息可能更重要.

If you're having performance issues with your recipe app, I'd suggest you submit a far more detailed question, with code samples, that articulates your particular performance problem. And I wouldn't be surprised if multi-threading was not part of the solution. Likely, appropriate use of indexes and a more judicious retrieval of information at any given point might be more critical.

这篇关于多线程数据库获取xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆