iPhone:NSOperationQueue 串行运行操作
我有一个单例 NSOperationQueue 来处理我的所有网络请求。然而,我注意到,当我运行一个特别长的操作时(该特定操作至少需要 25 秒),我的其他操作在其完成之前不会运行。
maxConcurrentOperationCount 设置为 NSOperationQueueDefaultMaxConcurrentOperationCount,所以我不认为这是问题所在。
有什么原因会发生这种情况吗?除了生成多个 NSOperationQueues(我不确定是否可行的解决方案,也不确定这是一个好主意)之外,解决此问题的最佳方法是什么?
谢谢。
I have a singleton NSOperationQueue that handles all of my network requests. I'm noticing, however, that when I have one particularly long operation running (this particular operation takes at least 25 seconds), my other operations don't run until it completes.
maxConcurrentOperationCount is set to NSOperationQueueDefaultMaxConcurrentOperationCount, so I don't believe that's the issue.
Any reason why this would be happening? Besides spawning multiple NSOperationQueues (a solution that I'm not sure would work, nor am I sure it's a good idea), what's the best way to fix this problem?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 NSOperationQueue 类参考
NSOperationQueueDefaultMaxConcurrentOperationCount 的意思是“默认的最大操作数是由 NSOperationQueue 对象根据当前系统条件动态确定的”。我没有看到任何说明默认值将是 > 1(尤其是在单 CPU 系统上)。
尝试调用
-setMaxConcurrentOperationCount:
显式设置更大的值,看看是否有帮助。According to the NSOperationQueue class reference
NSOperationQueueDefaultMaxConcurrentOperationCount
means that "the default maximum number of operations is determined dynamically by the NSOperationQueue object based on current system conditions." I don't see anything that says the default will be > 1 (especially on a single-CPU system).Try calling
-setMaxConcurrentOperationCount:
to explicitly set a larger value, and see if that helps.