NSOperationQueue
The NSOperationQueue class regulates the execution of a set of NSOperation objects. After being added to a queue, an operation remains in that queue until it is explicitly canceled or finishes executing its task. Operations within the queue (but not yet executing) are themselves organized according to priority levels and inter-operation object dependencies and are executed accordingly. An application may create multiple operation queues and submit operations to any of them.
NSOperationQueue클래스는 NSOperation객체의 집합을 실행을 조절한다. 큐를 추가한 후, 연산의 테스크가 실행하여 끝나던가 취소하기 전까지 큐안에 남아있다. 큐안에 연산은 레벨 순위와 내부연산객체의 의존관계에 따라 조직되고 실행된다. 어플리케이션은 멀티 연산 큐를 생성하고 누구라도 연산을 수행한다
Inter-operation dependencies provide an absolute execution order for operations, even if those operations are located in different operation queues. An operation object is not considered ready to execute until all of its dependent operations have finished executing. For operations that are ready to execute, the operation queue always executes the one with the highest priority relative to the other ready operations. For details on how to set priority levels and dependencies, see NSOperation Class Reference.
연산은 다른 연산 큐에 위치하고 있지만, 내부연산 의존관계는 연산에 대한 확실한 실행 순서를 제공한다. 연산 객체는 모든 연관된 연산이 끝나기 전까지 실행에 대한 준비를 하지 않는다. 실행을 위해 준비가 되는 연산에 대해 연산 큐는 언제나 다른 준비된 연산에 대한 가장 높은 우선 순위로 실행된다. 우선순위와 의존관계에 대해 자세하고 알고 싶다면 NSOperation 클래스 레퍼런스를 확인해라
You cannot directly remove an operation from a queue after it has been added. An operation remains in its queue until it reports that it is finished with its task. Finishing its task does not necessarily mean that the operation performed that task to completion. An operation can also be canceled. Canceling an operation object leaves the object in the queue but notifies the object that it should abort its task as quickly as possible. For currently executing operations, this means that the operation object’s work code must check the cancellation state, stop what it is doing, and mark itself as finished. For operations that are queued but not yet executing, the queue must still call the operation object’s start method so that it can processes the cancellation event and mark itself as finished.
큐에 추가한 후 연산을 직접 제거하는건 불가능하다. 이 연산은 테스크가 끝났다고 알리기 전까지 큐에 남아있다. 태스크 종료는 연산이 완료를 반드시 의미하지 않다. 연산 취소가능하다. 연산객체의 취소는 큐안에 객체가 떠나며 가능한 빠르게 태스크에 대해 거부됨을 객체에 알린다. 최근 실행하는 연산에 대해 객체의 작업이 어떤 이유로 멈추었는지 취소상태를 확인하는 코드가 필요하다. 아직 실행되지 않은 기다리고 있는 연산에 대해, 큐는 연산객의 시작 메소드가 호출되도록 이벤트 취소와 종료 상태를 진행 할수 있다
Operation queues usually provide the threads used to run their operations. In Mac OS X v10.6 and later, operation queues use the libdispatch library (also known as Grand Central Dispatch) to initiate the execution of their operations. As a result, operations are always executed on a separate thread, regardless of whether they are designated as concurrent or non-concurrent operations. In Mac OS X v10.5, however, operations are executed on separate threads only if their isConcurrent method returns NO. If that method returns YES, the operation object is expected to create its own thread (or start some asynchronous operation); the queue does not provide a thread for it.
연산 큐는 보통 그들의 연산 실행에 사용되는 스레드를 제공한다. Mac OS X 10.6, 이후 버전은 연산 큐는 연산들의 실행핼을 초기화 시키는 libdispatch라이브러리를 사용한다. 그 결과 병행이나 비병행 연산으로 디자인이 되어있더라도 연산은 언제나 분리된 스레드 상에서 실행되어진다. 하지만 10.5에서 연산은 오직 병행 메소드 결과가 NO 일때 분리된 스레드로 수행이 된다. 만약 메소드의 결과가 YES인 경우 연산 객체는 고유한 스레드가 생성될 (이거나 비동기 연산 시작할때) 것이다.
예제
@interface testObj : NSOperation
{
}
@end
NSOperationQueue *i_Queue;
testObj *qObj = [[testObj alloc]init];
[i_Queue addOperation:qObj];
[qObj release];
'iOS' 카테고리의 다른 글
iPhone TestCase 생성 (0) | 2011.01.18 |
---|---|
NSOperation (0) | 2011.01.11 |
NSNotificationCenter (0) | 2011.01.05 |
NSSearchPathForDirectoriesInDomains (0) | 2011.01.05 |
Reachability & SCNetworkReachability (0) | 2011.01.04 |