开发者

Objective C to Java : NSOperationQueue?

I'm trying to understand Objective C code and I'm stuck in this line

Code:

NSOperationQueue *queue = [[NSOperationQueue alloc] init];

I understand that this开发者_高级运维 line constructs a new instance of a class NSOperationQueue. But what does this instance of NSOperationQueue do? Can anyone explain that to me? As I am more familiar with Java, it would be very helpful if someone could suggest me an equivalent piece of code in Java.


The NSOperationQueue implements basically the same functionality as you can get from a ThreadPoolExecutor plus a BlockingQueue in Java.

That is it takes a collection of NSOperations (approximate to Runnabless in Java) and executes then asynchronously.

With the added bonus that the operation queue tunes itself to the current run-time conditions.


Runnables cannot be configured to have dependencies on each other, which is an important feature that NSOperation has. User may have to write custom codes (may use Future.get(), BlockingQueue.take()) to achieve the same effect.


Take a look at NSOperationQueue's documentation. Basically, it's a class that is designed to execute multiple NSOperation. These are somewhat similar to threads (and they are executed in a background thread by NSOperationQueue).

Here's some more reading, if you need more details: short tutorial and full documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜