相当于Java的BlockingQueue的Objective-C? [英] Objective-C equivalent of Java's BlockingQueue?

查看:62
本文介绍了相当于Java的BlockingQueue的Objective-C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过多年的Java开发,我才刚刚进入iPhone开发.我正在寻找与Java的解决方案

您可以简单地剥离NSOperation并在数据返回(加载完成)时发布通知.看看Dave Dribin的NSOperation并发博客文章,该文章展示了如何封装NSURLConnection会话:

http://www.dribin.org/dave/blog/archives/2009/05/05/concurrent_operations/

如果您不打算访问适合使用NSURLConnection的Web服务或站点,则可以直接使用TCP/IP或UDP来使用Cocoa异步套接字:

http://code.google.com/p/cocoaasyncsocket/

最好的问候,

I'm just getting into iPhone development after many years doing Java development. I'm looking for the Objective-C equivalent to Java's BlockingQueue. Is there something like that?

In case I'm going about things the wrong way, here's what I'm trying to achieve:

I want to display, one at a time, chunks of data pulled from a network server. To keep the user from noticing network lag, I want to always have a few chunks of data pre-fetched. In Java-land, I'd use a thread-safe queue between my fetching thread and my display thread.

解决方案

You can simply spin off an NSOperation and post a notification when the data has come back (finished loading). Take a look at Dave Dribin's blog post on concurrency with NSOperation that shows how to encapsulate an NSURLConnection session:

http://www.dribin.org/dave/blog/archives/2009/05/05/concurrent_operations/

If you are not talking about accessing a web service or site where NSURLConnection is appropriate, you can instead use Cocoa Async Socket if it's straight TCP/IP or UDP:

http://code.google.com/p/cocoaasyncsocket/

Best Regards,

这篇关于相当于Java的BlockingQueue的Objective-C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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