DispatchQueue

Tabber·2021년 7월 21일
0

Apple Document

목록 보기
10/12
Class

An object that manages the execution of tasks serially or concurrently on your app's main thread or on a background thread.
앱의 기본 스레드 또는 백그라운드 스레드에서 작업 실행을 직렬 또는 동시에 관리하는 개체입니다.

날씨앱에 날씨를 업데이트 해줄 코드.
업데이트 해주는 곳에 DispatchQueue를 사용함.

Dispatch queues are FIFO queues to which your application can submit tasks in the form of block objects. Dispatch queues execute tasks either serially or concurrently. Work submitted to dispatch queues executes on a pool of threads managed by the system. Except for the dispatch queue representing your app's main thread, the system makes no guarantees about which thread it uses to execute a task.
디스패치 대기열은 응용 프로그램이 블록 개체 형식으로 작업을 제출할 수 있는 FIFO 대기열입니다. 발송 대기열은 작업을 직렬 또는 동시에 실행합니다. 발송 대기열에 제출된 작업은 시스템에서 관리되는 스레드 풀에서 실행됩니다. 앱의 기본 스레드를 나타내는 디스패치 큐를 제외하고, 시스템은 앱이 작업을 실행하는 데 사용하는 스레드를 보장하지 않습니다.

You schedule work items synchronously or asynchronously. When you schedule a work item synchronously, your code waits until that item finishes execution. When you schedule a work item asynchronously, your code continues executing while the work item runs elsewhere.
작업 항목을 동기식 또는 비동기식으로 예약합니다. 작업 항목을 동기적으로 예약할 때 코드는 해당 항목의 실행이 완료될 때까지 기다립니다. 비동기식으로 작업 항목을 예약하면 작업 항목이 다른 곳에서 실행되는 동안 코드가 계속 실행됩니다.

Avoiding Excessive Thread Creation

When designing tasks for concurrent execution, do not call methods that block the current thread of execution. When a task scheduled by a concurrent dispatch queue blocks a thread, the system creates additional threads to run other queued concurrent tasks. If too many tasks block, the system may run out of threads for your app.
동시 실행을 위한 태스크를 설계할 때 현재 실행 스레드를 차단하는 메서드를 호출하지 마십시오. 동시 발송 대기열로 예약된 작업이 스레드를 차단하면 시스템은 대기열에 있는 다른 동시 태스크를 실행하기 위해 추가 스레드를 생성합니다. 너무 많은 태스크가 차단되면 시스템에 앱의 스레드가 부족해질 수 있습니다.

Another way that apps consume too many threads is by creating too many private concurrent dispatch queues. Because each dispatch queue consumes thread resources, creating additional concurrent dispatch queues exacerbates the thread consumption problem. Instead of creating private concurrent queues, submit tasks to one of the global concurrent dispatch queues. For serial tasks, set the target of your serial queue to one of the global concurrent queues. That way, you can maintain the serialized behavior of the queue while minimizing the number of separate queues creating threads.
앱이 너무 많은 스레드를 사용하는 또 다른 방법은 너무 많은 개인 동시 발송 대기열을 만드는 것입니다. 각 디스패치 큐는 스레드 리소스를 사용하기 때문에 추가 동시 디스패치 큐를 만들면 스레드 소비 문제가 악화됩니다. 개인 동시 대기열을 만드는 대신 전역 동시 발송 대기열 중 하나에 태스크를 제출하십시오. 직렬 태스크의 경우 직렬 큐의 대상을 글로벌 동시 대기열 중 하나로 설정합니다. 이렇게 하면 스레드를 만드는 별도의 대기열 수를 최소화하면서 대기열의 직렬화된 동작을 유지할 수 있습니다.

profile
iOS 정복중인 Tabber 입니다.

0개의 댓글